comparison bn_mp_prime_random_ex.c @ 190:d8254fc979e9 libtommath-orig LTM_0.35

Initial import of libtommath 0.35
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 08:59:30 +0000
parents d29b64170cf0
children
comparison
equal deleted inserted replaced
142:d29b64170cf0 190:d8254fc979e9
45 if (flags & LTM_PRIME_SAFE) { 45 if (flags & LTM_PRIME_SAFE) {
46 flags |= LTM_PRIME_BBS; 46 flags |= LTM_PRIME_BBS;
47 } 47 }
48 48
49 /* calc the byte size */ 49 /* calc the byte size */
50 bsize = (size>>3)+(size&7?1:0); 50 bsize = (size>>3) + ((size&7)?1:0);
51 51
52 /* we need a buffer of bsize bytes */ 52 /* we need a buffer of bsize bytes */
53 tmp = OPT_CAST(unsigned char) XMALLOC(bsize); 53 tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
54 if (tmp == NULL) { 54 if (tmp == NULL) {
55 return MP_MEM; 55 return MP_MEM;
56 } 56 }
57 57
58 /* calc the maskAND value for the MSbyte*/ 58 /* calc the maskAND value for the MSbyte*/
59 maskAND = 0xFF >> (8 - (size & 7)); 59 maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
60 60
61 /* calc the maskOR_msb */ 61 /* calc the maskOR_msb */
62 maskOR_msb = 0; 62 maskOR_msb = 0;
63 maskOR_msb_offset = (size - 2) >> 3; 63 maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
64 if (flags & LTM_PRIME_2MSB_ON) { 64 if (flags & LTM_PRIME_2MSB_ON) {
65 maskOR_msb |= 1 << ((size - 2) & 7); 65 maskOR_msb |= 1 << ((size - 2) & 7);
66 } else if (flags & LTM_PRIME_2MSB_OFF) { 66 } else if (flags & LTM_PRIME_2MSB_OFF) {
67 maskAND &= ~(1 << ((size - 2) & 7)); 67 maskAND &= ~(1 << ((size - 2) & 7));
68 } 68 }
69 69
70 /* get the maskOR_lsb */ 70 /* get the maskOR_lsb */
71 maskOR_lsb = 0; 71 maskOR_lsb = 1;
72 if (flags & LTM_PRIME_BBS) { 72 if (flags & LTM_PRIME_BBS) {
73 maskOR_lsb |= 3; 73 maskOR_lsb |= 3;
74 } 74 }
75 75
76 do { 76 do {