summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/crypt/encrypt.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/crypt/encrypt.c
parentInitial commit. (diff)
downloadwasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz
wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/crypt/encrypt.c')
-rw-r--r--libc-top-half/musl/src/crypt/encrypt.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/crypt/encrypt.c b/libc-top-half/musl/src/crypt/encrypt.c
new file mode 100644
index 0000000..216abc9
--- /dev/null
+++ b/libc-top-half/musl/src/crypt/encrypt.c
@@ -0,0 +1,52 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "crypt_des.h"
+
+static struct expanded_key __encrypt_key;
+
+void setkey(const char *key)
+{
+ unsigned char bkey[8];
+ int i, j;
+
+ for (i = 0; i < 8; i++) {
+ bkey[i] = 0;
+ for (j = 7; j >= 0; j--, key++)
+ bkey[i] |= (uint32_t)(*key & 1) << j;
+ }
+
+ __des_setkey(bkey, &__encrypt_key);
+}
+
+void encrypt(char *block, int edflag)
+{
+ struct expanded_key decrypt_key, *key;
+ uint32_t b[2];
+ int i, j;
+ char *p;
+
+ p = block;
+ for (i = 0; i < 2; i++) {
+ b[i] = 0;
+ for (j = 31; j >= 0; j--, p++)
+ b[i] |= (uint32_t)(*p & 1) << j;
+ }
+
+ 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 = block;
+ for (i = 0; i < 2; i++)
+ for (j = 31; j >= 0; j--)
+ *p++ = b[i]>>j & 1;
+}