/* * 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 * or http://www.opensolaris.org/os/licensing. * 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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. */ #ifndef _BIGNUM_H #define _BIGNUM_H #ifdef __cplusplus extern "C" { #endif #include #if defined(__sparcv9) || defined(__amd64) /* 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