summaryrefslogtreecommitdiffstats
path: root/src/crypto/des/des.c
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-09-24 23:03:06 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-09-24 23:03:06 +0000
commitc737bc23bc868fff21e5c1b95940813f709ea550 (patch)
treedd743d9d64af3145fe96b8d5fc2f3427544794bd /src/crypto/des/des.c
parent0267d647a4d272af8b9e7c91063d374f7e2775bb (diff)
parent3781a60670f92c3c6fca860cb4589495cefa2e56 (diff)
downloadexternal_boringssl-c737bc23bc868fff21e5c1b95940813f709ea550.zip
external_boringssl-c737bc23bc868fff21e5c1b95940813f709ea550.tar.gz
external_boringssl-c737bc23bc868fff21e5c1b95940813f709ea550.tar.bz2
am 3781a606: am 1e4884f6: external/boringssl: sync with upstream.
* commit '3781a60670f92c3c6fca860cb4589495cefa2e56': external/boringssl: sync with upstream.
Diffstat (limited to 'src/crypto/des/des.c')
-rw-r--r--src/crypto/des/des.c157
1 files changed, 79 insertions, 78 deletions
diff --git a/src/crypto/des/des.c b/src/crypto/des/des.c
index 9cd75f5..a5669a6 100644
--- a/src/crypto/des/des.c
+++ b/src/crypto/des/des.c
@@ -298,10 +298,8 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
0, 1, 1, 1, 1, 1, 1, 0};
uint32_t c, d, t, s, t2;
const uint8_t *in;
- uint32_t *k;
int i;
- k = &schedule->ks->deslong[0];
in = key->bytes;
c2l(in, c);
@@ -344,10 +342,10 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
/* table contained 0213 4657 */
t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL;
- *(k++) = ROTATE(t2, 30) & 0xffffffffL;
+ schedule->subkeys[i][0] = ROTATE(t2, 30) & 0xffffffffL;
t2 = ((s >> 16L) | (t & 0xffff0000L));
- *(k++) = ROTATE(t2, 26) & 0xffffffffL;
+ schedule->subkeys[i][1] = ROTATE(t2, 26) & 0xffffffffL;
}
}
@@ -382,7 +380,6 @@ void DES_set_odd_parity(DES_cblock *key) {
static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
uint32_t l, r, t, u;
- const uint32_t *s;
r = data[0];
l = data[1];
@@ -398,43 +395,42 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
r = ROTATE(r, 29) & 0xffffffffL;
l = ROTATE(l, 29) & 0xffffffffL;
- s = ks->ks->deslong;
/* I don't know if it is worth the effort of loop unrolling the
* inner loop */
if (enc) {
- D_ENCRYPT(l, r, 0); /* 1 */
- D_ENCRYPT(r, l, 2); /* 2 */
- D_ENCRYPT(l, r, 4); /* 3 */
- D_ENCRYPT(r, l, 6); /* 4 */
- D_ENCRYPT(l, r, 8); /* 5 */
- D_ENCRYPT(r, l, 10); /* 6 */
- D_ENCRYPT(l, r, 12); /* 7 */
- D_ENCRYPT(r, l, 14); /* 8 */
- D_ENCRYPT(l, r, 16); /* 9 */
- D_ENCRYPT(r, l, 18); /* 10 */
- D_ENCRYPT(l, r, 20); /* 11 */
- D_ENCRYPT(r, l, 22); /* 12 */
- D_ENCRYPT(l, r, 24); /* 13 */
- D_ENCRYPT(r, l, 26); /* 14 */
- D_ENCRYPT(l, r, 28); /* 15 */
- D_ENCRYPT(r, l, 30); /* 16 */
+ D_ENCRYPT(ks, l, r, 0);
+ D_ENCRYPT(ks, r, l, 1);
+ D_ENCRYPT(ks, l, r, 2);
+ D_ENCRYPT(ks, r, l, 3);
+ D_ENCRYPT(ks, l, r, 4);
+ D_ENCRYPT(ks, r, l, 5);
+ D_ENCRYPT(ks, l, r, 6);
+ D_ENCRYPT(ks, r, l, 7);
+ D_ENCRYPT(ks, l, r, 8);
+ D_ENCRYPT(ks, r, l, 9);
+ D_ENCRYPT(ks, l, r, 10);
+ D_ENCRYPT(ks, r, l, 11);
+ D_ENCRYPT(ks, l, r, 12);
+ D_ENCRYPT(ks, r, l, 13);
+ D_ENCRYPT(ks, l, r, 14);
+ D_ENCRYPT(ks, r, l, 15);
} else {
- D_ENCRYPT(l, r, 30); /* 16 */
- D_ENCRYPT(r, l, 28); /* 15 */
- D_ENCRYPT(l, r, 26); /* 14 */
- D_ENCRYPT(r, l, 24); /* 13 */
- D_ENCRYPT(l, r, 22); /* 12 */
- D_ENCRYPT(r, l, 20); /* 11 */
- D_ENCRYPT(l, r, 18); /* 10 */
- D_ENCRYPT(r, l, 16); /* 9 */
- D_ENCRYPT(l, r, 14); /* 8 */
- D_ENCRYPT(r, l, 12); /* 7 */
- D_ENCRYPT(l, r, 10); /* 6 */
- D_ENCRYPT(r, l, 8); /* 5 */
- D_ENCRYPT(l, r, 6); /* 4 */
- D_ENCRYPT(r, l, 4); /* 3 */
- D_ENCRYPT(l, r, 2); /* 2 */
- D_ENCRYPT(r, l, 0); /* 1 */
+ D_ENCRYPT(ks, l, r, 15);
+ D_ENCRYPT(ks, r, l, 14);
+ D_ENCRYPT(ks, l, r, 13);
+ D_ENCRYPT(ks, r, l, 12);
+ D_ENCRYPT(ks, l, r, 11);
+ D_ENCRYPT(ks, r, l, 10);
+ D_ENCRYPT(ks, l, r, 9);
+ D_ENCRYPT(ks, r, l, 8);
+ D_ENCRYPT(ks, l, r, 7);
+ D_ENCRYPT(ks, r, l, 6);
+ D_ENCRYPT(ks, l, r, 5);
+ D_ENCRYPT(ks, r, l, 4);
+ D_ENCRYPT(ks, l, r, 3);
+ D_ENCRYPT(ks, r, l, 2);
+ D_ENCRYPT(ks, l, r, 1);
+ D_ENCRYPT(ks, r, l, 0);
}
/* rotate and clear the top bits on machines with 8byte longs */
@@ -448,7 +444,6 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
uint32_t l, r, t, u;
- const uint32_t *s;
r = data[0];
l = data[1];
@@ -462,52 +457,51 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
r = ROTATE(r, 29) & 0xffffffffL;
l = ROTATE(l, 29) & 0xffffffffL;
- s = ks->ks->deslong;
/* I don't know if it is worth the effort of loop unrolling the
* inner loop */
if (enc) {
- D_ENCRYPT(l, r, 0); /* 1 */
- D_ENCRYPT(r, l, 2); /* 2 */
- D_ENCRYPT(l, r, 4); /* 3 */
- D_ENCRYPT(r, l, 6); /* 4 */
- D_ENCRYPT(l, r, 8); /* 5 */
- D_ENCRYPT(r, l, 10); /* 6 */
- D_ENCRYPT(l, r, 12); /* 7 */
- D_ENCRYPT(r, l, 14); /* 8 */
- D_ENCRYPT(l, r, 16); /* 9 */
- D_ENCRYPT(r, l, 18); /* 10 */
- D_ENCRYPT(l, r, 20); /* 11 */
- D_ENCRYPT(r, l, 22); /* 12 */
- D_ENCRYPT(l, r, 24); /* 13 */
- D_ENCRYPT(r, l, 26); /* 14 */
- D_ENCRYPT(l, r, 28); /* 15 */
- D_ENCRYPT(r, l, 30); /* 16 */
+ D_ENCRYPT(ks, l, r, 0);
+ D_ENCRYPT(ks, r, l, 1);
+ D_ENCRYPT(ks, l, r, 2);
+ D_ENCRYPT(ks, r, l, 3);
+ D_ENCRYPT(ks, l, r, 4);
+ D_ENCRYPT(ks, r, l, 5);
+ D_ENCRYPT(ks, l, r, 6);
+ D_ENCRYPT(ks, r, l, 7);
+ D_ENCRYPT(ks, l, r, 8);
+ D_ENCRYPT(ks, r, l, 9);
+ D_ENCRYPT(ks, l, r, 10);
+ D_ENCRYPT(ks, r, l, 11);
+ D_ENCRYPT(ks, l, r, 12);
+ D_ENCRYPT(ks, r, l, 13);
+ D_ENCRYPT(ks, l, r, 14);
+ D_ENCRYPT(ks, r, l, 15);
} else {
- D_ENCRYPT(l, r, 30); /* 16 */
- D_ENCRYPT(r, l, 28); /* 15 */
- D_ENCRYPT(l, r, 26); /* 14 */
- D_ENCRYPT(r, l, 24); /* 13 */
- D_ENCRYPT(l, r, 22); /* 12 */
- D_ENCRYPT(r, l, 20); /* 11 */
- D_ENCRYPT(l, r, 18); /* 10 */
- D_ENCRYPT(r, l, 16); /* 9 */
- D_ENCRYPT(l, r, 14); /* 8 */
- D_ENCRYPT(r, l, 12); /* 7 */
- D_ENCRYPT(l, r, 10); /* 6 */
- D_ENCRYPT(r, l, 8); /* 5 */
- D_ENCRYPT(l, r, 6); /* 4 */
- D_ENCRYPT(r, l, 4); /* 3 */
- D_ENCRYPT(l, r, 2); /* 2 */
- D_ENCRYPT(r, l, 0); /* 1 */
+ D_ENCRYPT(ks, l, r, 15);
+ D_ENCRYPT(ks, r, l, 14);
+ D_ENCRYPT(ks, l, r, 13);
+ D_ENCRYPT(ks, r, l, 12);
+ D_ENCRYPT(ks, l, r, 11);
+ D_ENCRYPT(ks, r, l, 10);
+ D_ENCRYPT(ks, l, r, 9);
+ D_ENCRYPT(ks, r, l, 8);
+ D_ENCRYPT(ks, l, r, 7);
+ D_ENCRYPT(ks, r, l, 6);
+ D_ENCRYPT(ks, l, r, 5);
+ D_ENCRYPT(ks, r, l, 4);
+ D_ENCRYPT(ks, l, r, 3);
+ D_ENCRYPT(ks, r, l, 2);
+ D_ENCRYPT(ks, l, r, 1);
+ D_ENCRYPT(ks, r, l, 0);
}
/* rotate and clear the top bits on machines with 8byte longs */
data[0] = ROTATE(l, 3) & 0xffffffffL;
data[1] = ROTATE(r, 3) & 0xffffffffL;
}
-static void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
- const DES_key_schedule *ks2,
- const DES_key_schedule *ks3) {
+/* DES_encrypt3 is not static because it's used in decrepit. */
+void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
+ const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
uint32_t l, r;
l = data[0];
@@ -525,9 +519,9 @@ static void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
data[1] = r;
}
-static void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
- const DES_key_schedule *ks2,
- const DES_key_schedule *ks3) {
+/* DES_decrypt3 is not static because it's used in decrepit. */
+void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
+ const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
uint32_t l, r;
l = data[0];
@@ -770,3 +764,10 @@ void DES_ede2_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
int enc) {
DES_ede3_cbc_encrypt(in, out, len, ks1, ks2, ks1, ivec, enc);
}
+
+
+/* Deprecated functions. */
+
+void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) {
+ DES_set_key(key, schedule);
+}