From darrenm@sac.sfbay.sun.com Tue Feb  5 11:20:25 2008
Received: from sunmail5.uk.sun.com (sunmail5.UK.Sun.COM [129.156.85.165])
	by sac.sfbay.sun.com (8.13.8+Sun/8.13.8) with ESMTP id m15JKOc0006809
	for <psarc-ext@sac.sfbay.sun.com>; Tue, 5 Feb 2008 11:20:25 -0800 (PST)
Received: from brm-avmta-1.central.sun.com (brm-avmta-1.Central.Sun.COM [129.147.4.11])
	by sunmail5.uk.sun.com (8.13.8+Sun/8.13.8/ENSMAIL,v2.2) with ESMTP id m15JKGBj002261;
	Tue, 5 Feb 2008 19:20:23 GMT
Received: from pmxchannel-daemon.brm-avmta-1.central.sun.com by
 brm-avmta-1.central.sun.com
 (Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
 id <0JVS001135PZB500@brm-avmta-1.central.sun.com>; Tue,
 05 Feb 2008 12:20:23 -0700 (MST)
Received: from dm-sfbay-02.sfbay.sun.com ([129.146.11.31])
 by brm-avmta-1.central.sun.com
 (Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005))
 with ESMTP id <0JVS00DAR5PXDBA0@brm-avmta-1.central.sun.com>; Tue,
 05 Feb 2008 12:20:21 -0700 (MST)
Received: from sac.sfbay.sun.com (new-sac.SFBay.Sun.COM [129.146.175.65])
	by dm-sfbay-02.sfbay.sun.com (8.13.8+Sun/8.13.8/ENSMAIL,v2.2)
 with ESMTP id m15JKLQ0055784; Tue, 05 Feb 2008 11:20:21 -0800 (PST)
Received: from sac.sfbay.sun.com (localhost [127.0.0.1])
	by sac.sfbay.sun.com (8.13.8+Sun/8.13.8) with ESMTP id m15J5Lxi006690; Tue,
 05 Feb 2008 11:05:21 -0800 (PST)
Received: (from darrenm@localhost)
	by sac.sfbay.sun.com (8.13.8+Sun/8.13.8/Submit) id m15J5Lmr006686; Tue,
 05 Feb 2008 11:05:21 -0800 (PST)
Date: Tue, 05 Feb 2008 11:05:21 -0800 (PST)
From: Darren J Moffat <darrenm@sac.sfbay.sun.com>
Subject: BIGNUM kernel module [PSARC/2008/080 Self Review]
To: PSARC-ext@sun.com
Cc: Ferenc.Rakoczi@sun.com, crypto-discuss@opensolaris.org
Message-id: <200802051905.m15J5Lmr006686@sac.sfbay.sun.com>
Content-transfer-encoding: 7BIT
X-PMX-Version: 5.2.0.264296
Status: RO
Content-Length: 3540


Template Version: @(#)sac_nextcase 1.64 07/13/07 SMI
This information is Copyright 2008 Sun Microsystems
1. Introduction
    1.1. Project/Component Working Name:
	 BIGNUM kernel module
    1.2. Name of Document Author/Supplier:
	 Author:  Ferenc Rakoczi
    1.3  Date of This Document:
	05 February, 2008
4. Technical Description

This case factors out the duplicated (copy/paste) BIGNUM code from the
existing "rsa" and "ncp" Kernel Crypto Provider modules and the userland
pkcs11_softtoken plugin for libpkcs11.  It does so by providing a new
consolidation private kernel/misc/bignum module.

The resulting new binaries are:

	kernel/misc/bignum
	kernel/misc/amd64/bignum
	kernel/misc/sparcv9/bignum
	platform/sun4u/kernel/misc/sparcv9/bignum


Additional $PLATFORM variants of bignum maybe added in the future and adding
one is not expected require an ARC review (even closed-approved automatic).

All interfaces exported from the module are Consolidation Private to ON.
Release binding is patch.

Since these are Consolidation Private no header file is included in SUNWhea.
The header file in the ON consolidation is $SRC/common/bignum/bignum.h

For reference they are:

  extern BIGNUM big_One;
  extern BIGNUM big_Two;
  BIG_ERR_CODE big_init(BIGNUM *number, int size);
  BIG_ERR_CODE big_extend(BIGNUM *number, int size);
  void big_finish(BIGNUM *number);
  void bytestring2bignum(BIGNUM *bn, uchar_t *kn, size_t len);
  void bignum2bytestring(uchar_t *kn, BIGNUM *bn, size_t len);
  BIG_ERR_CODE big_mont_rr(BIGNUM *result, BIGNUM *n);
  BIG_ERR_CODE big_modexp(BIGNUM *result, BIGNUM *a, BIGNUM *e,
      BIGNUM *n, BIGNUM *n_rr);
  BIG_ERR_CODE big_modexp_ext(BIGNUM *result, BIGNUM *a, BIGNUM *e,
      BIGNUM *n, BIGNUM *n_rr, big_modexp_ncp_info_t *info);
  BIG_ERR_CODE big_modexp_crt(BIGNUM *result, BIGNUM *a, BIGNUM *dmodpminus1,
      BIGNUM *dmodqminus1, BIGNUM *p, BIGNUM *q, BIGNUM *pinvmodq,
      BIGNUM *p_rr, BIGNUM *q_rr);
  BIG_ERR_CODE big_modexp_crt_ext(BIGNUM *result, BIGNUM *a,
      BIGNUM *dmodpminus1,
      BIGNUM *dmodqminus1, BIGNUM *p, BIGNUM *q, BIGNUM *pinvmodq,
      BIGNUM *p_rr, BIGNUM *q_rr, big_modexp_ncp_info_t *info);
  int big_cmp_abs(BIGNUM *a, BIGNUM *b);
  BIG_ERR_CODE randombignum(BIGNUM *r, int length);
  BIG_ERR_CODE big_div_pos(BIGNUM *result, BIGNUM *remainder,
      BIGNUM *aa, BIGNUM *bb);
  BIG_ERR_CODE big_ext_gcd_pos(BIGNUM *gcd, BIGNUM *cm, BIGNUM *ce,
      BIGNUM *m, BIGNUM *e);
  BIG_ERR_CODE big_add(BIGNUM *result, BIGNUM *aa, BIGNUM *bb);
  BIG_ERR_CODE big_add_abs(BIGNUM *result, BIGNUM *aa, BIGNUM *bb);
  BIG_ERR_CODE big_mul(BIGNUM *result, BIGNUM *aa, BIGNUM *bb);
  void big_shiftright(BIGNUM *result, BIGNUM *aa, int offs);
  BIG_ERR_CODE big_nextprime_pos(BIGNUM *result, BIGNUM *n);
  BIG_ERR_CODE big_nextprime_pos_ext(BIGNUM *result, BIGNUM *n,
      big_modexp_ncp_info_t *info);
  BIG_ERR_CODE big_sub_pos(BIGNUM *result, BIGNUM *aa, BIGNUM *bb);
  BIG_ERR_CODE big_copy(BIGNUM *dest, BIGNUM *src);
  BIG_ERR_CODE big_sub(BIGNUM *result, BIGNUM *aa, BIGNUM *bb);
  int big_bitlength(BIGNUM *n);
  BIG_ERR_CODE big_init1(BIGNUM *number, int size,
      BIG_CHUNK_TYPE *buf, int bufsize);
  BIG_ERR_CODE big_mont_mul(BIGNUM *ret,
      BIGNUM *a, BIGNUM *b, BIGNUM *n, BIG_CHUNK_TYPE n0);
  int big_is_zero(BIGNUM *n);
  BIG_CHUNK_TYPE big_n0(BIG_CHUNK_TYPE n);




6. Resources and Schedule
    6.4. Steering Committee requested information
   	6.4.1. Consolidation C-team Name:
		ON
    6.5. ARC review type: Automatic
    6.6. ARC Exposure: open


