aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch')
-rw-r--r--main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch155
1 files changed, 87 insertions, 68 deletions
diff --git a/main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch b/main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch
index a65049a56a..0a25d9061d 100644
--- a/main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch
+++ b/main/musl/1002-add-legacy-functions-setkey-and-encrypt.patch
@@ -1,108 +1,118 @@
-From ea610e10b6ea99dbb774b7231884002324ffc478 Mon Sep 17 00:00:00 2001
+From 8546e9be8757a9406a8c05fae9efc55eaab3e984 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Mon, 13 Jan 2014 13:05:14 +0200
Subject: [PATCH] add legacy functions setkey() and encrypt()
---
- src/crypt/crypt_des.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++----
- 1 file changed, 63 insertions(+), 5 deletions(-)
+ src/crypt/crypt_des.c | 12 +++++-----
+ src/crypt/encrypt.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 69 insertions(+), 6 deletions(-)
+ create mode 100644 src/crypt/encrypt.c
diff --git a/src/crypt/crypt_des.c b/src/crypt/crypt_des.c
-index dc95dca..05f69e7 100644
+index dc95dca..d5766a7 100644
--- a/src/crypt/crypt_des.c
+++ b/src/crypt/crypt_des.c
-@@ -55,6 +55,8 @@
-
- #include <stdint.h>
- #include <string.h>
-+#include <stdlib.h>
-+#include <unistd.h>
+@@ -692,7 +692,7 @@ static uint32_t setup_salt(uint32_t salt)
+ return saltbits;
+ }
- struct expanded_key {
- uint32_t l[16], r[16];
-@@ -755,8 +757,10 @@ static void des_setkey(const unsigned char *key, struct expanded_key *ekey)
+-static void des_setkey(const unsigned char *key, struct expanded_key *ekey)
++void __des_setkey(const unsigned char *key, struct expanded_key *ekey)
+ {
+ uint32_t k0, k1, rawkey0, rawkey1;
+ unsigned int shifts, round, i, ibit;
+@@ -753,7 +753,7 @@ static void des_setkey(const unsigned char *key, struct expanded_key *ekey)
+ /*
+ * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
*/
- static void do_des(uint32_t l_in, uint32_t r_in,
+-static void do_des(uint32_t l_in, uint32_t r_in,
++void __do_des(uint32_t l_in, uint32_t r_in,
uint32_t *l_out, uint32_t *r_out,
-- uint32_t count, uint32_t saltbits, const struct expanded_key *ekey)
-+ int32_t count, uint32_t saltbits, const struct expanded_key *ekey)
+ uint32_t count, uint32_t saltbits, const struct expanded_key *ekey)
{
-+ const uint32_t *rkl, *rkr;
-+ int klradd;
- uint32_t l, r;
+@@ -862,7 +862,7 @@ static void des_cipher(const unsigned char *in, unsigned char *out,
+ ((uint32_t)in[5] << 16) |
+ ((uint32_t)in[4] << 24);
- /*
-@@ -773,13 +777,24 @@ static void do_des(uint32_t l_in, uint32_t r_in,
- }
+- do_des(rawl, rawr, &l_out, &r_out, count, saltbits, ekey);
++ __do_des(rawl, rawr, &l_out, &r_out, count, saltbits, ekey);
+
+ out[0] = l_out >> 24;
+ out[1] = l_out >> 16;
+@@ -894,7 +894,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
+ if (*key)
+ key++;
}
+- des_setkey(keybuf, &ekey);
++ __des_setkey(keybuf, &ekey);
-+ if (count < 0) {
-+ count = -count;
-+ rkl = &ekey->l[15];
-+ rkr = &ekey->r[15];
-+ klradd = -1;
-+ } else {
-+ rkl = &ekey->l[0];
-+ rkr = &ekey->r[0];
-+ klradd = 1;
-+ }
-+
- while (count--) {
+ if (*setting == _PASSWORD_EFMT1) {
/*
- * Do each round.
- */
- unsigned int round = 16;
-- const uint32_t *kl = ekey->l;
-- const uint32_t *kr = ekey->r;
-+ const uint32_t *kl = rkl;
-+ const uint32_t *kr = rkr;
- uint32_t f;
- while (round--) {
- uint32_t r48l, r48r;
-@@ -802,8 +817,10 @@ static void do_des(uint32_t l_in, uint32_t r_in,
- * XOR with the permuted key.
- */
- f = (r48l ^ r48r) & saltbits;
-- r48l ^= f ^ *kl++;
-- r48r ^= f ^ *kr++;
-+ r48l ^= f ^ *kl;
-+ r48r ^= f ^ *kr;
-+ kl += klradd;
-+ kr += klradd;
- /*
- * Do S-box lookups (which shrink it back to 32 bits)
- * and do the P-box permutation at the same time.
-@@ -1016,3 +1033,44 @@ char *__crypt_des(const char *key, const char *setting, char *output)
+@@ -929,7 +929,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
+ q = keybuf;
+ while (q <= &keybuf[sizeof(keybuf) - 1] && *key)
+ *q++ ^= *key++ << 1;
+- des_setkey(keybuf, &ekey);
++ __des_setkey(keybuf, &ekey);
+ }
- return (setting[0]=='*') ? "x" : "*";
- }
+ memcpy(output, setting, 9);
+@@ -957,7 +957,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
+ /*
+ * Do it.
+ */
+- do_des(0, 0, &r0, &r1, count, setup_salt(salt), &ekey);
++ __do_des(0, 0, &r0, &r1, count, setup_salt(salt), &ekey);
+
+ /*
+ * Now encode the result...
+diff --git a/src/crypt/encrypt.c b/src/crypt/encrypt.c
+new file mode 100644
+index 0000000..3b414f1
+--- /dev/null
++++ b/src/crypt/encrypt.c
+@@ -0,0 +1,63 @@
++#include <stdint.h>
++#include <stdlib.h>
++#include <unistd.h>
++
++struct expanded_key {
++ uint32_t l[16], r[16];
++};
++
++void __des_setkey(const unsigned char *key, struct expanded_key *ekey);
++void __do_des(uint32_t l_in, uint32_t r_in,
++ uint32_t *l_out, uint32_t *r_out,
++ uint32_t count, uint32_t saltbits, const struct expanded_key *ekey);
++
+
+static struct expanded_key __encrypt_key;
+
+void setkey(const char *key)
+{
+ unsigned char bkey[8];
-+ const char *pkey = key;
+ int i, j;
+
+ for (i = 0; i < 8; i++) {
+ bkey[i] = 0;
-+ for (j = 7; j >= 0; j--, pkey++) {
-+ if (*pkey & 1)
++ for (j = 7; j >= 0; j--, key++) {
++ if (*key & 1)
+ bkey[i] |= 1 << j;
+ }
+ }
+
-+ des_setkey(bkey, &__encrypt_key);
++ __des_setkey(bkey, &__encrypt_key);
+}
+
+void encrypt(char *block, int edflag)
+{
-+ unsigned char *p;
++ struct expanded_key decrypt_key, *key;
+ uint32_t b[2];
+ int i, j;
++ char *p;
+
-+ p = (unsigned char*) block;
++ p = block;
+ for (i = 0; i < 2; i++) {
+ b[i] = 0;
+ for (j = 31; j >= 0; j--, p++)
@@ -110,9 +120,18 @@ index dc95dca..05f69e7 100644
+ b[i] |= 1 << j;
+ }
+
-+ do_des(b[0], b[1], b, b + 1, edflag ? -1 : 1, 0, &__encrypt_key);
++ key = &__encrypt_key;
++ if (edflag) {
++ key = &decrypt_key;
++ for (i = 0; i < 16; i++) {
++ decrypt_key.l[i] = __encrypt_key.l[15-i];
++ decrypt_key.r[i] = __encrypt_key.r[15-i];
++ }
++ }
++
++ __do_des(b[0], b[1], b, b + 1, 1, 0, key);
+
-+ p = (unsigned char*) block;
++ p = block;
+ for (i = 0; i < 2; i++)
+ for (j = 31; j >= 0; j--)
+ *p++ = (b[i] & (1 << j)) ? 1 : 0;