OLD | NEW |
1 /* crypto/rc2/rc2_skey.c */ | 1 /* crypto/rc2/rc2_skey.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 * SUCH DAMAGE. | 51 * SUCH DAMAGE. |
52 * | 52 * |
53 * The licence and distribution terms for any publically available version or | 53 * The licence and distribution terms for any publically available version or |
54 * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 * copied and put under another distribution licence | 55 * copied and put under another distribution licence |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include <openssl/rc2.h> | 59 #include <openssl/rc2.h> |
60 #include <openssl/crypto.h> | |
61 #ifdef OPENSSL_FIPS | |
62 #include <openssl/fips.h> | |
63 #endif | |
64 | |
65 #include "rc2_locl.h" | 60 #include "rc2_locl.h" |
66 | 61 |
67 static unsigned char key_table[256]={ | 62 static const unsigned char key_table[256]={ |
68 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79, | 63 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79, |
69 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e, | 64 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e, |
70 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5, | 65 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5, |
71 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32, | 66 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32, |
72 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22, | 67 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22, |
73 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c, | 68 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c, |
74 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f, | 69 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f, |
75 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26, | 70 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26, |
76 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b, | 71 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b, |
77 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7, | 72 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7, |
(...skipping 14 matching lines...) Expand all Loading... |
92 #if defined(_MSC_VER) && defined(_ARM_) | 87 #if defined(_MSC_VER) && defined(_ARM_) |
93 #pragma optimize("g",off) | 88 #pragma optimize("g",off) |
94 #endif | 89 #endif |
95 | 90 |
96 /* It has come to my attention that there are 2 versions of the RC2 | 91 /* It has come to my attention that there are 2 versions of the RC2 |
97 * key schedule. One which is normal, and anther which has a hook to | 92 * key schedule. One which is normal, and anther which has a hook to |
98 * use a reduced key length. | 93 * use a reduced key length. |
99 * BSAFE uses the 'retarded' version. What I previously shipped is | 94 * BSAFE uses the 'retarded' version. What I previously shipped is |
100 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses | 95 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses |
101 * a version where the bits parameter is the same as len*8 */ | 96 * a version where the bits parameter is the same as len*8 */ |
102 | |
103 #ifdef OPENSSL_FIPS | |
104 void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits) | 97 void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits) |
105 { | 98 { |
106 if (FIPS_mode()) | |
107 FIPS_BAD_ABORT(RC2) | |
108 private_RC2_set_key(key, len, data, bits); | |
109 } | |
110 void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, | |
111 int bits) | |
112 #else | |
113 void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits) | |
114 #endif | |
115 { | |
116 int i,j; | 99 int i,j; |
117 unsigned char *k; | 100 unsigned char *k; |
118 RC2_INT *ki; | 101 RC2_INT *ki; |
119 unsigned int c,d; | 102 unsigned int c,d; |
120 | 103 |
121 k= (unsigned char *)&(key->data[0]); | 104 k= (unsigned char *)&(key->data[0]); |
122 *k=0; /* for if there is a zero length key */ | 105 *k=0; /* for if there is a zero length key */ |
123 | 106 |
124 if (len > 128) len=128; | 107 if (len > 128) len=128; |
125 if (bits <= 0) bits=1024; | 108 if (bits <= 0) bits=1024; |
(...skipping 27 matching lines...) Expand all Loading... |
153 | 136 |
154 /* copy from bytes into RC2_INT's */ | 137 /* copy from bytes into RC2_INT's */ |
155 ki= &(key->data[63]); | 138 ki= &(key->data[63]); |
156 for (i=127; i>=0; i-=2) | 139 for (i=127; i>=0; i-=2) |
157 *(ki--)=((k[i]<<8)|k[i-1])&0xffff; | 140 *(ki--)=((k[i]<<8)|k[i-1])&0xffff; |
158 } | 141 } |
159 | 142 |
160 #if defined(_MSC_VER) | 143 #if defined(_MSC_VER) |
161 #pragma optimize("",on) | 144 #pragma optimize("",on) |
162 #endif | 145 #endif |
OLD | NEW |