bignum.h revision 14ea4bb737263733ad80a36b4f73f681c30a6b45
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _BIGNUM_H
#define _BIGNUM_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
typedef int BIG_ERR_CODE;
#define BITSINBYTE 8
#ifdef BIGNUM_CHUNK_32
#define BIG_CHUNK_SIZE 32
#define BIG_CHUNK_TYPE uint32_t
#define BIG_CHUNK_HIGHBIT 0x80000000
#define BIG_CHUNK_ALLBITS 0xffffffff
#define BIG_CHUNK_LOWHALFBITS 0xffff
#define BIG_CHUNK_HALF_HIGHBIT 0x8000
#else
#define BIG_CHUNK_SIZE 64
#define BIG_CHUNK_TYPE uint64_t
#define BIG_CHUNK_HIGHBIT 0x8000000000000000ULL
#define BIG_CHUNK_ALLBITS 0xffffffffffffffffULL
#define BIG_CHUNK_LOWHALFBITS 0xffffffffULL
#define BIG_CHUNK_HALF_HIGHBIT 0x80000000ULL
#endif
sizeof (BIG_CHUNK_TYPE))
/*
* leading 0's are permitted
* 0 should be represented by size>=1, size>=len>=1, sign=1,
* value[i]=0 for 0<i<len
*/
typedef struct {
int size; /* the size of memory allocated for value (in words) */
int len; /* the number of words that hold valid data in value */
int sign; /* 1 for nonnegative, -1 for negative */
int malloced; /* 1 if value was malloced 0 if not */
} BIGNUM;
typedef struct {
BIGNUM p; /* p */
BIGNUM q; /* q */
BIGNUM n; /* n = p * q (the modulus) */
BIGNUM d; /* private exponent */
BIGNUM e; /* public exponent */
} RSAkey;
typedef struct {
BIGNUM q; /* q (160-bit prime) */
BIGNUM p; /* p (<size-bit> prime) */
BIGNUM g; /* g (the base) */
BIGNUM x; /* private key (< q) */
BIGNUM y; /* = g^x mod p */
BIGNUM k; /* k (random number < q) */
BIGNUM r; /* r (signiture 1st part) */
BIGNUM s; /* s (signiture 1st part) */
BIGNUM v; /* v (verification value - should be = r ) */
} DSAkey;
#define BIGTMPSIZE 65
#define BIG_TRUE 1
#define BIG_FALSE 0
/* error codes */
#define BIG_OK 0
#define BIG_NO_MEM -1
#define BIG_INVALID_ARGS -2
#define BIG_DIV_BY_0 -3
#define BIG_NO_RANDOM -4
#define BIG_TEST_FAILED -5
#define arraysize(x) (sizeof (x) / sizeof (x[0]))
#ifdef MODEXP_FLOAT
#endif
int ncp_big_is_zero(BIGNUM *n);
void *reqp);
int ncp_big_bitlength(BIGNUM *n);
#ifdef __cplusplus
}
#endif
#endif /* _BIGNUM_H */