diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2014-04-24 21:31:03 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2014-04-24 21:31:03 +0000 |
commit | ed44b84d25ab31484a1c54e2479cd779a189c716 (patch) | |
tree | 9ff58dd8c9d527f8dac5463f76a452ca1c34face /lib/libcrypto | |
parent | c0bebe74381af27313b5baa2bb56f3332d6203d2 (diff) |
Try to clean the maze of <openssl/bn.h> defines regarding the BN internals.
The intent of this change is to only keep support for two kind of architectures:
- those with 32-bit int and long, and 64-bit long long, where
``long * long -> long long'' multiplication routines are available.
- those with 64-bit int and long, and no 128-bit long long type.
This gets rid of the SIXTY_FOUR_BIT_LONG, SIXTY_FOUR_BIT (not the same!),
THIRTY_TWO_BIT, SIXTEEN_BIT and EIGHT_BIT defines.
After this change, the types and defines are as follows:
arch: 64bit 32bit rationale
BN_LLONG undefined defined defined if l * l -> ll
BN_ULLONG undefined u long long result of BN_LONG * BN_LONG
BN_ULONG u long u int native register size
BN_LONG long int the same, signed
BN_BITS 128 64 size of 2*BN_ULONG in bits
BN_BYTES 8 4 size of 2*BN_ULONG in bytes
BN_BITS2 64 32 BN_BITS / 2
Tested on various 32-bit and 64-bit OpenBSD systems of various endianness.
Diffstat (limited to 'lib/libcrypto')
-rw-r--r-- | lib/libcrypto/bn/asm/parisc-mont.pl | 14 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn.h | 53 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_div.c | 71 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_gf2m.c | 15 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_lcl.h | 27 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_lib.c | 29 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_mod.c | 9 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_nist.c | 8 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_prime.h | 10 | ||||
-rw-r--r-- | lib/libcrypto/bn/bn_prime.pl | 20 |
10 files changed, 28 insertions, 228 deletions
diff --git a/lib/libcrypto/bn/asm/parisc-mont.pl b/lib/libcrypto/bn/asm/parisc-mont.pl index 4a766a87fb2..c38cebd1568 100644 --- a/lib/libcrypto/bn/asm/parisc-mont.pl +++ b/lib/libcrypto/bn/asm/parisc-mont.pl @@ -40,7 +40,7 @@ # of arithmetic operations, most notably multiplications. It requires # more memory references, most notably to tp[num], but this doesn't # seem to exhaust memory port capacity. And indeed, dedicated PA-RISC -# 2.0 code path, provides virtually same performance as pa-risc2[W].s: +# 2.0 code path provides virtually same performance as pa-risc2[W].s: # it's ~10% better for shortest key length and ~10% worse for longest # one. # @@ -87,16 +87,6 @@ if ($flavour =~ /64/) { $POP ="ldw"; $POPMB ="ldwm"; $BN_SZ =$SIZE_T; - if (open CONF,"<${dir}../../opensslconf.h") { - while(<CONF>) { - if (m/#\s*define\s+SIXTY_FOUR_BIT/) { - $BN_SZ=8; - $LEVEL="2.0"; - last; - } - } - close CONF; - } } $FRAME=8*$SIZE_T+$FRAME_MARKER; # 8 saved regs + frame marker @@ -988,6 +978,8 @@ foreach (split("\n",$code)) { # assemble 2.0 instructions in 32-bit mode... s/^\s+([a-z]+)([\S]*)\s+([\S]*)/&assemble($1,$2,$3)/e if ($BN_SZ==4); + s/\bbv\b/bve/gm if ($SIZE_T==8); + print $_,"\n"; } close STDOUT; diff --git a/lib/libcrypto/bn/bn.h b/lib/libcrypto/bn/bn.h index 4959232179b..74005ed2541 100644 --- a/lib/libcrypto/bn/bn.h +++ b/lib/libcrypto/bn/bn.h @@ -167,18 +167,14 @@ extern "C" { * using "long long's", are 32bit, and are not using my assembler code. */ /* #define BN_DIV2W */ -/* assuming long is 64bit - this is the DEC Alpha - * unsigned long long is only 64 bits :-(, don't define - * BN_LLONG for the DEC Alpha */ -#ifdef SIXTY_FOUR_BIT_LONG -#define BN_ULLONG unsigned long long +#ifdef _LP64 +#undef BN_LLONG #define BN_ULONG unsigned long #define BN_LONG long #define BN_BITS 128 #define BN_BYTES 8 #define BN_BITS2 64 #define BN_BITS4 32 -#define BN_MASK (0xffffffffffffffffffffffffffffffffLL) #define BN_MASK2 (0xffffffffffffffffL) #define BN_MASK2l (0xffffffffL) #define BN_MASK2h (0xffffffff00000000L) @@ -190,51 +186,16 @@ extern "C" { #define BN_DEC_NUM 19 #define BN_HEX_FMT1 "%lX" #define BN_HEX_FMT2 "%016lX" -#endif - -/* This is where the long long data type is 64 bits, but long is 32. - * For machines where there are 64bit registers, this is the mode to use. - * IRIX, on R4000 and above should use this mode, along with the relevant - * assembler code :-). Do NOT define BN_LLONG. - */ -#ifdef SIXTY_FOUR_BIT -#undef BN_LLONG -#undef BN_ULLONG -#define BN_ULONG unsigned long long -#define BN_LONG long long -#define BN_BITS 128 -#define BN_BYTES 8 -#define BN_BITS2 64 -#define BN_BITS4 32 -#define BN_MASK2 (0xffffffffffffffffLL) -#define BN_MASK2l (0xffffffffL) -#define BN_MASK2h (0xffffffff00000000LL) -#define BN_MASK2h1 (0xffffffff80000000LL) -#define BN_TBIT (0x8000000000000000LL) -#define BN_DEC_CONV (10000000000000000000ULL) -#define BN_DEC_FMT1 "%llu" -#define BN_DEC_FMT2 "%019llu" -#define BN_DEC_NUM 19 -#define BN_HEX_FMT1 "%llX" -#define BN_HEX_FMT2 "%016llX" -#endif - -#ifdef THIRTY_TWO_BIT -#ifdef BN_LLONG -# if defined(_WIN32) && !defined(__GNUC__) -# define BN_ULLONG unsigned __int64 -# define BN_MASK (0xffffffffffffffffI64) -# else -# define BN_ULLONG unsigned long long -# define BN_MASK (0xffffffffffffffffLL) -# endif -#endif +#else +#define BN_ULLONG unsigned long long +#define BN_LLONG #define BN_ULONG unsigned int #define BN_LONG int #define BN_BITS 64 #define BN_BYTES 4 #define BN_BITS2 32 #define BN_BITS4 16 +#define BN_MASK (0xffffffffffffffffLL) #define BN_MASK2 (0xffffffffL) #define BN_MASK2l (0xffff) #define BN_MASK2h1 (0xffff8000L) @@ -248,8 +209,6 @@ extern "C" { #define BN_HEX_FMT2 "%08X" #endif -#define BN_DEFAULT_BITS 1280 - #define BN_FLG_MALLOCED 0x01 #define BN_FLG_STATIC_DATA 0x02 #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, diff --git a/lib/libcrypto/bn/bn_div.c b/lib/libcrypto/bn/bn_div.c index 871f29e34f8..e3e06ac054b 100644 --- a/lib/libcrypto/bn/bn_div.c +++ b/lib/libcrypto/bn/bn_div.c @@ -61,72 +61,6 @@ #include "cryptlib.h" #include "bn_lcl.h" - -/* The old slow way */ -#if 0 -int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, - BN_CTX *ctx) - { - int i,nm,nd; - int ret = 0; - BIGNUM *D; - - bn_check_top(m); - bn_check_top(d); - if (BN_is_zero(d)) - { - BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); - return(0); - } - - if (BN_ucmp(m,d) < 0) - { - if (rem != NULL) - { if (BN_copy(rem,m) == NULL) return(0); } - if (dv != NULL) BN_zero(dv); - return(1); - } - - BN_CTX_start(ctx); - D = BN_CTX_get(ctx); - if (dv == NULL) dv = BN_CTX_get(ctx); - if (rem == NULL) rem = BN_CTX_get(ctx); - if (D == NULL || dv == NULL || rem == NULL) - goto end; - - nd=BN_num_bits(d); - nm=BN_num_bits(m); - if (BN_copy(D,d) == NULL) goto end; - if (BN_copy(rem,m) == NULL) goto end; - - /* The next 2 are needed so we can do a dv->d[0]|=1 later - * since BN_lshift1 will only work once there is a value :-) */ - BN_zero(dv); - if(bn_wexpand(dv,1) == NULL) goto end; - dv->top=1; - - if (!BN_lshift(D,D,nm-nd)) goto end; - for (i=nm-nd; i>=0; i--) - { - if (!BN_lshift1(dv,dv)) goto end; - if (BN_ucmp(rem,D) >= 0) - { - dv->d[0]|=1; - if (!BN_usub(rem,rem,D)) goto end; - } -/* CAN IMPROVE (and have now :=) */ - if (!BN_rshift1(D,D)) goto end; - } - rem->neg=BN_is_zero(rem)?0:m->neg; - dv->neg=m->neg^d->neg; - ret = 1; - end: - BN_CTX_end(ctx); - return(ret); - } - -#else - #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \ && !defined(BN_DIV3W) # if defined(__GNUC__) && __GNUC__>=2 @@ -151,7 +85,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, q; \ }) # define REMAINDER_IS_ALREADY_CALCULATED -# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG) +# elif defined(__x86_64) /* * Same story here, but it's 128-bit by 64-bit division. Wow! * <appro@fy.chalmers.se> @@ -333,7 +267,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, #ifdef BN_LLONG BN_ULLONG t2; -#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) +#if defined(BN_DIV2W) && !defined(bn_div_words) q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); #else q=bn_div_words(n0,n1,d0); @@ -435,4 +369,3 @@ err: BN_CTX_end(ctx); return(0); } -#endif diff --git a/lib/libcrypto/bn/bn_gf2m.c b/lib/libcrypto/bn/bn_gf2m.c index 68a5faa52da..a75c98ac0ea 100644 --- a/lib/libcrypto/bn/bn_gf2m.c +++ b/lib/libcrypto/bn/bn_gf2m.c @@ -103,7 +103,7 @@ static const BN_ULONG SQR_tb[16] = { 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85 }; /* Platform-specific macros to accelerate squaring. */ -#if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) +#ifdef _LP64 #define SQR1(w) \ SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \ SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \ @@ -114,8 +114,7 @@ static const BN_ULONG SQR_tb[16] = SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \ SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \ SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF] -#endif -#ifdef THIRTY_TWO_BIT +#else #define SQR1(w) \ SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \ SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF] @@ -130,9 +129,9 @@ static const BN_ULONG SQR_tb[16] = * The caller MUST ensure that the variables have the right amount * of space allocated. */ -#ifdef THIRTY_TWO_BIT static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) { +#ifndef _LP64 register BN_ULONG h, l, s; BN_ULONG tab[8], top2b = a >> 30; register BN_ULONG a1, a2, a4; @@ -160,11 +159,7 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } *r1 = h; *r0 = l; - } -#endif -#if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) -static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) - { +#else register BN_ULONG h, l, s; BN_ULONG tab[16], top3b = a >> 61; register BN_ULONG a1, a2, a4, a8; @@ -200,8 +195,8 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } *r1 = h; *r0 = l; - } #endif + } /* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1, * result is a polynomial r with degree < 4 * BN_BITS2 - 1 diff --git a/lib/libcrypto/bn/bn_lcl.h b/lib/libcrypto/bn/bn_lcl.h index e46cbc2ef85..c3aa584066c 100644 --- a/lib/libcrypto/bn/bn_lcl.h +++ b/lib/libcrypto/bn/bn_lcl.h @@ -144,26 +144,14 @@ extern "C" { * (with draws in between). Very small exponents are often selected * with low Hamming weight, so we use w = 1 for b <= 23. */ -#if 1 #define BN_window_bits_for_exponent_size(b) \ ((b) > 671 ? 6 : \ (b) > 239 ? 5 : \ (b) > 79 ? 4 : \ (b) > 23 ? 3 : 1) -#else -/* Old SSLeay/OpenSSL table. - * Maximum window size was 5, so this table differs for b==1024; - * but it coincides for other interesting values (b==160, b==512). - */ -#define BN_window_bits_for_exponent_size(b) \ - ((b) > 255 ? 5 : \ - (b) > 127 ? 4 : \ - (b) > 17 ? 3 : 1) -#endif - -/* BN_mod_exp_mont_conttime is based on the assumption that the +/* BN_mod_exp_mont_consttime is based on the assumption that the * L1 data cache line width of the target processor is at least * the following value. */ @@ -234,7 +222,7 @@ extern "C" { * * <appro@fy.chalmers.se> */ -# if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) +# if defined(__alpha) # if defined(__GNUC__) && __GNUC__>=2 # define BN_UMULT_HIGH(a,b) ({ \ register BN_ULONG ret; \ @@ -243,7 +231,7 @@ extern "C" { : "r"(a), "r"(b)); \ ret; }) # endif /* compiler */ -# elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG) +# elif defined(_ARCH_PPC) && defined(_LP64) # if defined(__GNUC__) && __GNUC__>=2 # define BN_UMULT_HIGH(a,b) ({ \ register BN_ULONG ret; \ @@ -252,8 +240,7 @@ extern "C" { : "r"(a), "r"(b)); \ ret; }) # endif /* compiler */ -# elif (defined(__x86_64) || defined(__x86_64__)) && \ - (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) +# elif defined(__x86_64) || defined(__x86_64__) # if defined(__GNUC__) && __GNUC__>=2 # define BN_UMULT_HIGH(a,b) ({ \ register BN_ULONG ret,discard; \ @@ -268,7 +255,7 @@ extern "C" { : "a"(a),"g"(b) \ : "cc"); # endif -# elif defined(__mips) && (defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)) +# elif defined(__mips) && defined(_LP64) # if defined(__GNUC__) && __GNUC__>=2 # if __GNUC__>=4 && __GNUC_MINOR__>=4 /* "h" constraint is no more since 4.4 */ # define BN_UMULT_HIGH(a,b) (((__uint128_t)(a)*(b))>>64) @@ -397,10 +384,6 @@ extern "C" { #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) -#define LLBITS(a) ((a)&BN_MASKl) -#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) -#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2) - #define mul64(l,h,bl,bh) \ { \ BN_ULONG m,m1,lt,ht; \ diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index c8de547ba55..9787a31dbbf 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -160,7 +160,7 @@ int BN_num_bits_word(BN_ULONG l) 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, }; -#if defined(SIXTY_FOUR_BIT_LONG) +#ifdef _LP64 if (l & 0xffffffff00000000L) { if (l & 0xffff000000000000L) @@ -181,32 +181,8 @@ int BN_num_bits_word(BN_ULONG l) } } else -#else -#ifdef SIXTY_FOUR_BIT - if (l & 0xffffffff00000000LL) - { - if (l & 0xffff000000000000LL) - { - if (l & 0xff00000000000000LL) - { - return(bits[(int)(l>>56)]+56); - } - else return(bits[(int)(l>>48)]+48); - } - else - { - if (l & 0x0000ff0000000000LL) - { - return(bits[(int)(l>>40)]+40); - } - else return(bits[(int)(l>>32)]+32); - } - } - else -#endif #endif { -#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) if (l & 0xffff0000L) { if (l & 0xff000000L) @@ -214,13 +190,10 @@ int BN_num_bits_word(BN_ULONG l) else return(bits[(int)(l>>16L)]+16); } else -#endif { -#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) if (l & 0xff00L) return(bits[(int)(l>>8)]+8); else -#endif return(bits[(int)(l )] ); } } diff --git a/lib/libcrypto/bn/bn_mod.c b/lib/libcrypto/bn/bn_mod.c index 77d6ddb91a5..6c439402dd8 100644 --- a/lib/libcrypto/bn/bn_mod.c +++ b/lib/libcrypto/bn/bn_mod.c @@ -115,15 +115,6 @@ #include "bn_lcl.h" -#if 0 /* now just a #define */ -int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) - { - return(BN_div(NULL,rem,m,d,ctx)); - /* note that rem->neg == m->neg (unless the remainder is zero) */ - } -#endif - - int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) { /* like BN_mod, but returns non-negative remainder diff --git a/lib/libcrypto/bn/bn_nist.c b/lib/libcrypto/bn/bn_nist.c index 4d4a7b86df4..d793644e272 100644 --- a/lib/libcrypto/bn/bn_nist.c +++ b/lib/libcrypto/bn/bn_nist.c @@ -321,7 +321,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) #define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0)); #define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n) # if _BYTE_ORDER == _LITTLE_ENDIAN -# if defined(__arch64__) +# if defined(_LP64) # define NIST_INT64 long # else # define NIST_INT64 long long @@ -340,9 +340,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) } #define bn_cp_32(to, n, from, m) (to)[n] = (m>=0)?((from)[m]):0; #define bn_32_set_0(to, n) (to)[n] = (BN_ULONG)0; -# if defined(_WIN32) && !defined(__GNUC__) -# define NIST_INT64 __int64 -# elif defined(BN_LLONG) +# if defined(BN_LLONG) # define NIST_INT64 long long # endif #endif /* BN_BITS2 != 64 */ @@ -594,7 +592,7 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } else if (carry < 0) { - /* it's a bit more comlicated logic in this case. + /* it's a bit more complicated logic in this case. * if bn_add_words yields no carry, then result * has to be adjusted by unconditionally *adding* * the modulus. but if it does, then result has diff --git a/lib/libcrypto/bn/bn_prime.h b/lib/libcrypto/bn/bn_prime.h index 51d2194febd..ccdeca5afa3 100644 --- a/lib/libcrypto/bn/bn_prime.h +++ b/lib/libcrypto/bn/bn_prime.h @@ -56,13 +56,8 @@ * [including the GNU Public Licence.] */ -#ifndef EIGHT_BIT #define NUMPRIMES 2048 typedef unsigned short prime_t; -#else -#define NUMPRIMES 54 -typedef unsigned char prime_t; -#endif static const prime_t primes[NUMPRIMES]= { 2, 3, 5, 7, 11, 13, 17, 19, @@ -71,9 +66,7 @@ static const prime_t primes[NUMPRIMES]= 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, - 227, 229, 233, 239, 241, 251, -#ifndef EIGHT_BIT - 257, 263, + 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, @@ -323,5 +316,4 @@ static const prime_t primes[NUMPRIMES]= 17609,17623,17627,17657,17659,17669,17681,17683, 17707,17713,17729,17737,17747,17749,17761,17783, 17789,17791,17807,17827,17837,17839,17851,17863, -#endif }; diff --git a/lib/libcrypto/bn/bn_prime.pl b/lib/libcrypto/bn/bn_prime.pl index 3fafb6f3e90..eb73f0bfa6f 100644 --- a/lib/libcrypto/bn/bn_prime.pl +++ b/lib/libcrypto/bn/bn_prime.pl @@ -90,30 +90,14 @@ print <<\EOF; EOF -for ($i=0; $i <= $#primes; $i++) - { - if ($primes[$i] > 256) - { - $eight=$i; - last; - } - } - -printf "#ifndef EIGHT_BIT\n"; printf "#define NUMPRIMES %d\n",$num; printf "typedef unsigned short prime_t;\n"; -printf "#else\n"; -printf "#define NUMPRIMES %d\n",$eight; -printf "typedef unsigned char prime_t;\n"; -printf "#endif\n"; -print "static const prime_t primes[NUMPRIMES]=\n\t{\n\t"; -$init=0; +print "static const prime_t primes[NUMPRIMES]=\n{\n\t"; for ($i=0; $i <= $#primes; $i++) { - printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++); printf("\n\t") if (($i%8) == 0) && ($i != 0); printf("%4d,",$primes[$i]); } -print "\n#endif\n\t};\n"; +print "\n};\n"; |