Mercurial > dropbear
comparison src/ciphers/rc6.c @ 191:1c15b283127b libtomcrypt-orig
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 13:23:02 +0000 |
parents | |
children | 39d5d58461d6 |
comparison
equal
deleted
inserted
replaced
143:5d99163f7e32 | 191:1c15b283127b |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 | |
12 /** | |
13 @file rc6.c | |
14 RC6 code by Tom St Denis | |
15 */ | |
16 #include "tomcrypt.h" | |
17 | |
18 #ifdef RC6 | |
19 | |
20 const struct ltc_cipher_descriptor rc6_desc = | |
21 { | |
22 "rc6", | |
23 3, | |
24 8, 128, 16, 20, | |
25 &rc6_setup, | |
26 &rc6_ecb_encrypt, | |
27 &rc6_ecb_decrypt, | |
28 &rc6_test, | |
29 &rc6_done, | |
30 &rc6_keysize, | |
31 NULL, NULL, NULL, NULL, NULL, NULL, NULL | |
32 }; | |
33 | |
34 static const ulong32 stab[44] = { | |
35 0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL, | |
36 0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL, | |
37 0x9b58ecf3UL, 0x399066acUL, 0xd7c7e065UL, 0x75ff5a1eUL, 0x1436d3d7UL, 0xb26e4d90UL, 0x50a5c749UL, 0xeedd4102UL, | |
38 0x8d14babbUL, 0x2b4c3474UL, 0xc983ae2dUL, 0x67bb27e6UL, 0x05f2a19fUL, 0xa42a1b58UL, 0x42619511UL, 0xe0990ecaUL, | |
39 0x7ed08883UL, 0x1d08023cUL, 0xbb3f7bf5UL, 0x5976f5aeUL, 0xf7ae6f67UL, 0x95e5e920UL, 0x341d62d9UL, 0xd254dc92UL, | |
40 0x708c564bUL, 0x0ec3d004UL, 0xacfb49bdUL, 0x4b32c376UL }; | |
41 | |
42 /** | |
43 Initialize the RC6 block cipher | |
44 @param key The symmetric key you wish to pass | |
45 @param keylen The key length in bytes | |
46 @param num_rounds The number of rounds desired (0 for default) | |
47 @param skey The key in as scheduled by this function. | |
48 @return CRYPT_OK if successful | |
49 */ | |
50 #ifdef LTC_CLEAN_STACK | |
51 static int _rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) | |
52 #else | |
53 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) | |
54 #endif | |
55 { | |
56 ulong32 L[64], S[50], A, B, i, j, v, s, l; | |
57 | |
58 LTC_ARGCHK(key != NULL); | |
59 LTC_ARGCHK(skey != NULL); | |
60 | |
61 /* test parameters */ | |
62 if (num_rounds != 0 && num_rounds != 20) { | |
63 return CRYPT_INVALID_ROUNDS; | |
64 } | |
65 | |
66 /* key must be between 64 and 1024 bits */ | |
67 if (keylen < 8 || keylen > 128) { | |
68 return CRYPT_INVALID_KEYSIZE; | |
69 } | |
70 | |
71 /* copy the key into the L array */ | |
72 for (A = i = j = 0; i < (ulong32)keylen; ) { | |
73 A = (A << 8) | ((ulong32)(key[i++] & 255)); |