--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/components/openssl/openssl-1.0.1/engines/t4/eng_t4_bignum.h Fri May 03 16:10:11 2013 -0700
@@ -0,0 +1,287 @@
+/*
+ * This product includes cryptographic software developed by the OpenSSL
+ * Project for use in the OpenSSL Toolkit (http://www.openssl.org/).
+ */
+
+/*
+ * ====================================================================
+ * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * [email protected].
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ */
+
+/*
+ * This file is a copy of the ON gate's usr/src/common/bignum/bignum.h file
+ */
+
+#ifndef _BIGNUM_H
+#define _BIGNUM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+
+#if defined(__sparcv9) || defined(__amd64) || defined(__sparc)
+ /* 64-bit chunk size */
+#ifndef UMUL64
+#define UMUL64 /* 64-bit multiplication results are supported */
+#endif
+#else
+#define BIGNUM_CHUNK_32
+#endif
+
+
+#define BITSINBYTE 8
+
+/* Bignum "digits" (aka "chunks" or "words") are either 32- or 64-bits */
+#ifdef BIGNUM_CHUNK_32
+#define BIG_CHUNK_SIZE 32
+#define BIG_CHUNK_TYPE uint32_t
+#define BIG_CHUNK_TYPE_SIGNED int32_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_TYPE_SIGNED int64_t
+#define BIG_CHUNK_HIGHBIT 0x8000000000000000ULL
+#define BIG_CHUNK_ALLBITS 0xffffffffffffffffULL
+#define BIG_CHUNK_LOWHALFBITS 0xffffffffULL
+#define BIG_CHUNK_HALF_HIGHBIT 0x80000000ULL
+#endif
+
+#define BITLEN2BIGNUMLEN(x) ((x) > 0 ? \
+ ((((x) - 1) / BIG_CHUNK_SIZE) + 1) : 0)
+#define CHARLEN2BIGNUMLEN(x) ((x) > 0 ? \
+ ((((x) - 1) / sizeof (BIG_CHUNK_TYPE)) + 1) : 0)
+
+#define BIGNUM_WORDSIZE (BIG_CHUNK_SIZE / BITSINBYTE) /* word size in bytes */
+#define BIG_CHUNKS_FOR_160BITS BITLEN2BIGNUMLEN(160)
+
+
+/*
+ * 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 {
+ /* size and len in units of BIG_CHUNK_TYPE words */
+ uint32_t size; /* size of memory allocated for value */
+ uint32_t len; /* number of valid data words in value */
+ int sign; /* 1 for nonnegative, -1 for negative */
+ int malloced; /* 1 if value was malloced, 0 if not */
+ BIG_CHUNK_TYPE *value;
+} BIGNUM;
+
+#define BIGTMPSIZE 65
+
+#define BIG_TRUE 1
+#define BIG_FALSE 0
+
+typedef int BIG_ERR_CODE;
+
+/* 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_GENERAL_ERR -5
+#define BIG_TEST_FAILED -6
+#define BIG_BUFFER_TOO_SMALL -7
+
+/*
+ * this is not an error code, but should be different from possible error codes
+ */
+#define RND_TEST_VALUE_SUPPLIED -8
+
+
+#define arraysize(x) (sizeof (x) / sizeof (x[0]))
+
+typedef BIG_ERR_CODE (*big_modexp_ncp_func_ptr)(BIGNUM *result,
+ BIGNUM *ma, BIGNUM *e, BIGNUM *n,
+ BIGNUM *tmp, BIG_CHUNK_TYPE n0, void *ncp, void *req);
+
+typedef struct {
+ big_modexp_ncp_func_ptr func;
+ void *ncp;
+ void *reqp;
+} big_modexp_ncp_info_t;
+
+#ifdef YF_MODEXP
+BIG_ERR_CODE big_modexp_ncp_yf(BIGNUM *result, BIGNUM *ma, BIGNUM *e, BIGNUM *n,
+ BIGNUM *tmp, BIG_CHUNK_TYPE n0);
+#endif
+
+#ifdef YF_MONTMUL
+BIG_ERR_CODE big_mont_mul_yf(BIGNUM *ret,
+ BIGNUM *a, BIGNUM *b, BIGNUM *n, BIG_CHUNK_TYPE n0);
+#endif
+
+#ifdef YF_MPMUL
+BIG_ERR_CODE big_mp_mul_yf(BIGNUM *ret, BIGNUM *a, BIGNUM *b);
+void mpmul_arr_yf(uint64_t *res, uint64_t *m1, uint64_t *m2, int len);
+#endif
+
+#ifdef USE_FLOATING_POINT
+void conv_d16_to_i32(uint32_t *i32, double *d16, int64_t *tmp, int ilen);
+void conv_i32_to_d32(double *d32, uint32_t *i32, int len);
+void conv_i32_to_d16(double *d16, uint32_t *i32, int len);
+void conv_i32_to_d32_and_d16(double *d32, double *d16,
+ uint32_t *i32, int len);
+void mont_mulf_noconv(uint32_t *result, double *dm1, double *dm2, double *dt,
+ double *dn, uint32_t *nint, int nlen, double dn0);
+#endif /* USE_FLOATING_POINT */
+
+extern BIGNUM big_One;
+extern BIGNUM big_Two;
+
+void printbignum(char *aname, BIGNUM *a);
+
+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 big_random(BIGNUM *r, size_t length,
+ int (*rfunc)(void *, size_t), boolean_t precise);
+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);
+void big_mul_arr_64(uint64_t *result, uint64_t *a, uint64_t *b, int alen);
+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);
+
+
+/*
+ * Kernel bignum module: module integrity test
+ */
+extern int bignum_fips_check(void);
+
+#if defined(HWCAP)
+
+#if (BIG_CHUNK_SIZE != 32)
+#error HWCAP works only with 32-bit bignum chunks
+#endif
+
+#define BIG_MUL_SET_VEC(r, a, len, digit) \
+ (*big_mul_set_vec_impl)(r, a, len, digit)
+#define BIG_MUL_ADD_VEC(r, a, len, digit) \
+ (*big_mul_add_vec_impl)(r, a, len, digit)
+#define BIG_MUL_VEC(r, a, alen, b, blen) \
+ (*big_mul_vec_impl)(r, a, alen, b, blen)
+#define BIG_SQR_VEC(r, a, len) \
+ (*big_sqr_vec_impl)(r, a, len)
+
+extern BIG_CHUNK_TYPE (*big_mul_set_vec_impl)
+ (BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int len, BIG_CHUNK_TYPE digit);
+extern BIG_CHUNK_TYPE (*big_mul_add_vec_impl)
+ (BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int len, BIG_CHUNK_TYPE digit);
+extern void (*big_mul_vec_impl)
+ (BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int alen, BIG_CHUNK_TYPE *b,
+ int blen);
+extern void (*big_sqr_vec_impl)
+ (BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int len);
+
+#else /* ! HWCAP */
+
+#define BIG_MUL_SET_VEC(r, a, len, digit) big_mul_set_vec(r, a, len, digit)
+#define BIG_MUL_ADD_VEC(r, a, len, digit) big_mul_add_vec(r, a, len, digit)
+#define BIG_MUL_VEC(r, a, alen, b, blen) big_mul_vec(r, a, alen, b, blen)
+#define BIG_SQR_VEC(r, a, len) big_sqr_vec(r, a, len)
+
+extern BIG_CHUNK_TYPE big_mul_set_vec(BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a,
+ int len, BIG_CHUNK_TYPE d);
+extern BIG_CHUNK_TYPE big_mul_add_vec(BIG_CHUNK_TYPE *r,
+ BIG_CHUNK_TYPE *a, int len, BIG_CHUNK_TYPE d);
+extern void big_mul_vec(BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int alen,
+ BIG_CHUNK_TYPE *b, int blen);
+extern void big_sqr_vec(BIG_CHUNK_TYPE *r, BIG_CHUNK_TYPE *a, int len);
+
+#endif /* HWCAP */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BIGNUM_H */