summaryrefslogtreecommitdiffhomepage
path: root/libtomcrypt/src/modes/lrw
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2018-02-09 21:44:05 +0800
committerMatt Johnston <matt@ucc.asn.au>2018-02-09 21:44:05 +0800
commit4f2eb1914bdac3ed3ee504ad86061281dbe0d074 (patch)
tree078293375c3f3ee2d485cf9559a08d65d460786a /libtomcrypt/src/modes/lrw
parentd72f50ff3284e15124a0f233c26339229fe305ac (diff)
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Diffstat (limited to 'libtomcrypt/src/modes/lrw')
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_decrypt.c8
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_done.c12
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_encrypt.c10
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_getiv.c8
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_process.c26
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_setiv.c18
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_start.c30
-rw-r--r--libtomcrypt/src/modes/lrw/lrw_test.c20
8 files changed, 58 insertions, 74 deletions
diff --git a/libtomcrypt/src/modes/lrw/lrw_decrypt.c b/libtomcrypt/src/modes/lrw/lrw_decrypt.c
index e2858c0..bfedb64 100644
--- a/libtomcrypt/src/modes/lrw/lrw_decrypt.c
+++ b/libtomcrypt/src/modes/lrw/lrw_decrypt.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
*/
#include "tomcrypt.h"
@@ -46,6 +44,6 @@ int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_done.c b/libtomcrypt/src/modes/lrw/lrw_done.c
index e123d28..0088f62 100644
--- a/libtomcrypt/src/modes/lrw/lrw_done.c
+++ b/libtomcrypt/src/modes/lrw/lrw_done.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
*/
#include "tomcrypt.h"
@@ -22,12 +20,12 @@
@param lrw The state to terminate
@return CRYPT_OK if successful
*/
-int lrw_done(symmetric_LRW *lrw)
+int lrw_done(symmetric_LRW *lrw)
{
int err;
LTC_ARGCHK(lrw != NULL);
-
+
if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
return err;
}
@@ -37,6 +35,6 @@ int lrw_done(symmetric_LRW *lrw)
}
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_encrypt.c b/libtomcrypt/src/modes/lrw/lrw_encrypt.c
index d84cbdd..0738648 100644
--- a/libtomcrypt/src/modes/lrw/lrw_encrypt.c
+++ b/libtomcrypt/src/modes/lrw/lrw_encrypt.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
*/
#include "tomcrypt.h"
@@ -16,7 +14,7 @@
*/
#ifdef LTC_LRW_MODE
-
+
/**
LRW encrypt blocks
@param pt The plaintext
@@ -45,6 +43,6 @@ int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_getiv.c b/libtomcrypt/src/modes/lrw/lrw_getiv.c
index 575e322..6dcd96d 100644
--- a/libtomcrypt/src/modes/lrw/lrw_getiv.c
+++ b/libtomcrypt/src/modes/lrw/lrw_getiv.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
*/
#include "tomcrypt.h"
@@ -40,6 +38,6 @@ int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw)
}
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_process.c b/libtomcrypt/src/modes/lrw/lrw_process.c
index 25661e7..0896bc6 100644
--- a/libtomcrypt/src/modes/lrw/lrw_process.c
+++ b/libtomcrypt/src/modes/lrw/lrw_process.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
*/
#include "tomcrypt.h"
@@ -30,7 +28,7 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
{
unsigned char prod[16];
int x, err;
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
int y;
#endif
@@ -49,18 +47,18 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
/* increment IV */
for (x = 15; x >= 0; x--) {
lrw->IV[x] = (lrw->IV[x] + 1) & 255;
- if (lrw->IV[x]) {
+ if (lrw->IV[x]) {
break;
}
}
/* update pad */
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
/* for each byte changed we undo it's affect on the pad then add the new product */
for (; x < 16; x++) {
#ifdef LTC_FAST
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(lrw->pad + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][lrw->IV[x]][y])) ^ *((LTC_FAST_TYPE *)(&lrw->PC[x][(lrw->IV[x]-1)&255][y]));
+ *(LTC_FAST_TYPE_PTR_CAST(lrw->pad + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][lrw->IV[x]][y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][(lrw->IV[x]-1)&255][y]));
}
#else
for (y = 0; y < 16; y++) {
@@ -75,7 +73,7 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
/* xor prod */
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(ct + x)) = *((LTC_FAST_TYPE *)(pt + x)) ^ *((LTC_FAST_TYPE *)(prod + x));
+ *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(pt + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x));
}
#else
for (x = 0; x < 16; x++) {
@@ -92,19 +90,19 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
if ((err = cipher_descriptor[lrw->cipher].ecb_decrypt(ct, ct, &lrw->key)) != CRYPT_OK) {
return err;
}
- }
+ }
/* xor prod */
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(ct + x)) = *((LTC_FAST_TYPE *)(ct + x)) ^ *((LTC_FAST_TYPE *)(prod + x));
+ *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(ct + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x));
}
#else
for (x = 0; x < 16; x++) {
ct[x] = ct[x] ^ prod[x];
}
#endif
-
+
/* move to next */
pt += 16;
ct += 16;
@@ -113,8 +111,8 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
return CRYPT_OK;
}
-
+
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_setiv.c b/libtomcrypt/src/modes/lrw/lrw_setiv.c
index 2ff9a80..5c04157 100644
--- a/libtomcrypt/src/modes/lrw/lrw_setiv.c
+++ b/libtomcrypt/src/modes/lrw/lrw_setiv.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
*/
#include "tomcrypt.h"
@@ -27,7 +25,7 @@
int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
{
int err;
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
unsigned char T[16];
int x, y;
#endif
@@ -51,12 +49,12 @@ int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
return CRYPT_OK;
}
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16);
for (x = 1; x < 16; x++) {
#ifdef LTC_FAST
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&lrw->PC[x][IV[x]][y]));
+ *(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][IV[x]][y]));
}
#else
for (y = 0; y < 16; y++) {
@@ -65,8 +63,8 @@ int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
#endif
}
XMEMCPY(lrw->pad, T, 16);
-#else
- gcm_gf_mult(lrw->tweak, IV, lrw->pad);
+#else
+ gcm_gf_mult(lrw->tweak, IV, lrw->pad);
#endif
return CRYPT_OK;
@@ -74,6 +72,6 @@ int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_start.c b/libtomcrypt/src/modes/lrw/lrw_start.c
index f378789..e13d3bd 100644
--- a/libtomcrypt/src/modes/lrw/lrw_start.c
+++ b/libtomcrypt/src/modes/lrw/lrw_start.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
*/
#include "tomcrypt.h"
@@ -19,9 +17,9 @@
/**
Initialize the LRW context
- @param cipher The cipher desired, must be a 128-bit block cipher
+ @param cipher The cipher desired, must be a 128-bit block cipher
@param IV The index value, must be 128-bits
- @param key The cipher key
+ @param key The cipher key
@param keylen The length of the cipher key in octets
@param tweak The tweak value (second key), must be 128-bits
@param num_rounds The number of rounds for the cipher (0 == default)
@@ -32,19 +30,19 @@ int lrw_start( int cipher,
const unsigned char *IV,
const unsigned char *key, int keylen,
const unsigned char *tweak,
- int num_rounds,
+ int num_rounds,
symmetric_LRW *lrw)
{
int err;
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
unsigned char B[16];
int x, y, z, t;
#endif
- LTC_ARGCHK(IV != NULL);
- LTC_ARGCHK(key != NULL);
- LTC_ARGCHK(tweak != NULL);
- LTC_ARGCHK(lrw != NULL);
+ LTC_ARGCHK(IV != NULL);
+ LTC_ARGCHK(key != NULL);
+ LTC_ARGCHK(tweak != NULL);
+ LTC_ARGCHK(lrw != NULL);
#ifdef LTC_FAST
if (16 % sizeof(LTC_FAST_TYPE)) {
@@ -69,7 +67,7 @@ int lrw_start( int cipher,
/* copy the IV and tweak */
XMEMCPY(lrw->tweak, tweak, 16);
-#ifdef LRW_TABLES
+#ifdef LTC_LRW_TABLES
/* setup tables */
/* generate the first table as it has no shifting (from which we make the other tables) */
zeromem(B, 16);
@@ -88,8 +86,8 @@ int lrw_start( int cipher,
}
lrw->PC[x][y][0] = gcm_shift_table[t<<1];
lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
- }
- }
+ }
+ }
#endif
/* generate first pad */
@@ -98,6 +96,6 @@ int lrw_start( int cipher,
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/lrw/lrw_test.c b/libtomcrypt/src/modes/lrw/lrw_test.c
index 63e014a..7762d47 100644
--- a/libtomcrypt/src/modes/lrw/lrw_test.c
+++ b/libtomcrypt/src/modes/lrw/lrw_test.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
*/
#include "tomcrypt.h"
@@ -88,7 +86,7 @@ int lrw_test(void)
}
/* check pad against expected tweak */
- if (XMEMCMP(tests[x].expected_tweak, lrw.pad, 16)) {
+ if (compare_testvector(tests[x].expected_tweak, 16, lrw.pad, 16, "LRW Tweak", x)) {
lrw_done(&lrw);
return CRYPT_FAIL_TESTVECTOR;
}
@@ -99,13 +97,13 @@ int lrw_test(void)
return err;
}
- if (XMEMCMP(buf[0], tests[x].C, 16)) {
+ if (compare_testvector(buf[0], 16, tests[x].C, 16, "LRW Encrypt", x)) {
lrw_done(&lrw);
return CRYPT_FAIL_TESTVECTOR;
}
/* process block */
- if ((err = lrw_setiv(tests[x].IV, 16, &lrw)) != CRYPT_OK) {
+ if ((err = lrw_setiv(tests[x].IV, 16, &lrw)) != CRYPT_OK) {
lrw_done(&lrw);
return err;
}
@@ -115,15 +113,15 @@ int lrw_test(void)
return err;
}
- if (XMEMCMP(buf[1], tests[x].P, 16)) {
+ if (compare_testvector(buf[1], 16, tests[x].P, 16, "LRW Decrypt", x)) {
lrw_done(&lrw);
return CRYPT_FAIL_TESTVECTOR;
}
if ((err = lrw_done(&lrw)) != CRYPT_OK) {
return err;
}
- }
- return CRYPT_OK;
+ }
+ return CRYPT_OK;
#endif
}
@@ -131,6 +129,6 @@ int lrw_test(void)
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */