summaryrefslogtreecommitdiffhomepage
path: root/libtomcrypt/src/ciphers/kseed.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtomcrypt/src/ciphers/kseed.c')
-rw-r--r--libtomcrypt/src/ciphers/kseed.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/libtomcrypt/src/ciphers/kseed.c b/libtomcrypt/src/ciphers/kseed.c
index a163c95..e12fdc7 100644
--- a/libtomcrypt/src/ciphers/kseed.c
+++ b/libtomcrypt/src/ciphers/kseed.c
@@ -5,8 +5,6 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
/**
@@ -29,7 +27,7 @@ const struct ltc_cipher_descriptor kseed_desc = {
&kseed_test,
&kseed_done,
&kseed_keysize,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
static const ulong32 SS0[256] = {
@@ -201,41 +199,41 @@ static const ulong32 KCi[16] = {
*/
int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
- int i;
- ulong32 tmp, k1, k2, k3, k4;
+ int i;
+ ulong32 tmp, k1, k2, k3, k4;
- if (keylen != 16) {
- return CRYPT_INVALID_KEYSIZE;
- }
-
- if (num_rounds != 16 && num_rounds != 0) {
- return CRYPT_INVALID_ROUNDS;
- }
+ if (keylen != 16) {
+ return CRYPT_INVALID_KEYSIZE;
+ }
- /* load key */
- LOAD32H(k1, key);
- LOAD32H(k2, key+4);
- LOAD32H(k3, key+8);
- LOAD32H(k4, key+12);
+ if (num_rounds != 16 && num_rounds != 0) {
+ return CRYPT_INVALID_ROUNDS;
+ }
- for (i = 0; i < 16; i++) {
- skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
- skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
- if (i&1) {
- tmp = k3;
- k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
- k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
- } else {
- tmp = k1;
- k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
- k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
+ /* load key */
+ LOAD32H(k1, key);
+ LOAD32H(k2, key+4);
+ LOAD32H(k3, key+8);
+ LOAD32H(k4, key+12);
+
+ for (i = 0; i < 16; i++) {
+ skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
+ skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
+ if (i&1) {
+ tmp = k3;
+ k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
+ k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
+ } else {
+ tmp = k1;
+ k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
+ k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
}
/* reverse keys for decrypt */
skey->kseed.dK[2*(15-i)+0] = skey->kseed.K[2*i+0];
skey->kseed.dK[2*(15-i)+1] = skey->kseed.K[2*i+1];
- }
+ }
- return CRYPT_OK;
+ return CRYPT_OK;
}
static void rounds(ulong32 *P, ulong32 *K)
@@ -275,7 +273,7 @@ int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
Decrypts a block of text with SEED
@param ct The input ciphertext (16 bytes)
@param pt The output plaintext (16 bytes)
- @param skey The key as scheduled
+ @param skey The key as scheduled
@return CRYPT_OK if successful
*/
int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
@@ -293,11 +291,12 @@ int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key
return CRYPT_OK;
}
-/** Terminate the context
+/** Terminate the context
@param skey The scheduled key
*/
void kseed_done(symmetric_key *skey)
{
+ LTC_UNUSED_PARAM(skey);
}
/**
@@ -345,7 +344,8 @@ int kseed_test(void)
kseed_setup(tests[x].key, 16, 0, &skey);
kseed_ecb_encrypt(tests[x].pt, buf[0], &skey);
kseed_ecb_decrypt(buf[0], buf[1], &skey);
- if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
+ if (compare_testvector(buf[0], 16, tests[x].ct, 16, "KSEED Encrypt", x) ||
+ compare_testvector(buf[1], 16, tests[x].pt, 16, "KSEED Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
@@ -371,6 +371,6 @@ int kseed_keysize(int *keysize)
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */