aboutsummaryrefslogtreecommitdiff
path: root/openssl-1.1.0h/crypto/rc5/rc5_enc.c
diff options
context:
space:
mode:
authorWojtek Kosior <wk@koszkonutek-tmp.pl.eu.org>2021-04-30 00:33:56 +0200
committerWojtek Kosior <wk@koszkonutek-tmp.pl.eu.org>2021-04-30 00:33:56 +0200
commitaa4d426b4d3527d7e166df1a05058c9a4a0f6683 (patch)
tree4ff17ce8b89a2321b9d0ed4bcfc37c447bcb6820 /openssl-1.1.0h/crypto/rc5/rc5_enc.c
downloadsmtps-and-pop3s-console-program-master.tar.gz
smtps-and-pop3s-console-program-master.zip
initial/final commitHEADmaster
Diffstat (limited to 'openssl-1.1.0h/crypto/rc5/rc5_enc.c')
-rw-r--r--openssl-1.1.0h/crypto/rc5/rc5_enc.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/openssl-1.1.0h/crypto/rc5/rc5_enc.c b/openssl-1.1.0h/crypto/rc5/rc5_enc.c
new file mode 100644
index 0000000..58631de
--- /dev/null
+++ b/openssl-1.1.0h/crypto/rc5/rc5_enc.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdio.h>
+#include <openssl/rc5.h>
+#include "rc5_locl.h"
+
+void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,
+ long length, RC5_32_KEY *ks, unsigned char *iv,
+ int encrypt)
+{
+ register unsigned long tin0, tin1;
+ register unsigned long tout0, tout1, xor0, xor1;
+ register long l = length;
+ unsigned long tin[2];
+
+ if (encrypt) {
+ c2l(iv, tout0);
+ c2l(iv, tout1);
+ iv -= 8;
+ for (l -= 8; l >= 0; l -= 8) {
+ c2l(in, tin0);
+ c2l(in, tin1);
+ tin0 ^= tout0;
+ tin1 ^= tout1;
+ tin[0] = tin0;
+ tin[1] = tin1;
+ RC5_32_encrypt(tin, ks);
+ tout0 = tin[0];
+ l2c(tout0, out);
+ tout1 = tin[1];
+ l2c(tout1, out);
+ }
+ if (l != -8) {
+ c2ln(in, tin0, tin1, l + 8);
+ tin0 ^= tout0;
+ tin1 ^= tout1;
+ tin[0] = tin0;
+ tin[1] = tin1;
+ RC5_32_encrypt(tin, ks);
+ tout0 = tin[0];
+ l2c(tout0, out);
+ tout1 = tin[1];
+ l2c(tout1, out);
+ }
+ l2c(tout0, iv);
+ l2c(tout1, iv);
+ } else {
+ c2l(iv, xor0);
+ c2l(iv, xor1);
+ iv -= 8;
+ for (l -= 8; l >= 0; l -= 8) {
+ c2l(in, tin0);
+ tin[0] = tin0;
+ c2l(in, tin1);
+ tin[1] = tin1;
+ RC5_32_decrypt(tin, ks);
+ tout0 = tin[0] ^ xor0;
+ tout1 = tin[1] ^ xor1;
+ l2c(tout0, out);
+ l2c(tout1, out);
+ xor0 = tin0;
+ xor1 = tin1;
+ }
+ if (l != -8) {
+ c2l(in, tin0);
+ tin[0] = tin0;
+ c2l(in, tin1);
+ tin[1] = tin1;
+ RC5_32_decrypt(tin, ks);
+ tout0 = tin[0] ^ xor0;
+ tout1 = tin[1] ^ xor1;
+ l2cn(tout0, tout1, out, l + 8);
+ xor0 = tin0;
+ xor1 = tin1;
+ }
+ l2c(xor0, iv);
+ l2c(xor1, iv);
+ }
+ tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
+ tin[0] = tin[1] = 0;
+}
+
+void RC5_32_encrypt(unsigned long *d, RC5_32_KEY *key)
+{
+ RC5_32_INT a, b, *s;
+
+ s = key->data;
+
+ a = d[0] + s[0];
+ b = d[1] + s[1];
+ E_RC5_32(a, b, s, 2);
+ E_RC5_32(a, b, s, 4);
+ E_RC5_32(a, b, s, 6);
+ E_RC5_32(a, b, s, 8);
+ E_RC5_32(a, b, s, 10);
+ E_RC5_32(a, b, s, 12);
+ E_RC5_32(a, b, s, 14);
+ E_RC5_32(a, b, s, 16);
+ if (key->rounds == 12) {
+ E_RC5_32(a, b, s, 18);
+ E_RC5_32(a, b, s, 20);
+ E_RC5_32(a, b, s, 22);
+ E_RC5_32(a, b, s, 24);
+ } else if (key->rounds == 16) {
+ /* Do a full expansion to avoid a jump */
+ E_RC5_32(a, b, s, 18);
+ E_RC5_32(a, b, s, 20);
+ E_RC5_32(a, b, s, 22);
+ E_RC5_32(a, b, s, 24);
+ E_RC5_32(a, b, s, 26);
+ E_RC5_32(a, b, s, 28);
+ E_RC5_32(a, b, s, 30);
+ E_RC5_32(a, b, s, 32);
+ }
+ d[0] = a;
+ d[1] = b;
+}
+
+void RC5_32_decrypt(unsigned long *d, RC5_32_KEY *key)
+{
+ RC5_32_INT a, b, *s;
+
+ s = key->data;
+
+ a = d[0];
+ b = d[1];
+ if (key->rounds == 16) {
+ D_RC5_32(a, b, s, 32);
+ D_RC5_32(a, b, s, 30);
+ D_RC5_32(a, b, s, 28);
+ D_RC5_32(a, b, s, 26);
+ /* Do a full expansion to avoid a jump */
+ D_RC5_32(a, b, s, 24);
+ D_RC5_32(a, b, s, 22);
+ D_RC5_32(a, b, s, 20);
+ D_RC5_32(a, b, s, 18);
+ } else if (key->rounds == 12) {
+ D_RC5_32(a, b, s, 24);
+ D_RC5_32(a, b, s, 22);
+ D_RC5_32(a, b, s, 20);
+ D_RC5_32(a, b, s, 18);
+ }
+ D_RC5_32(a, b, s, 16);
+ D_RC5_32(a, b, s, 14);
+ D_RC5_32(a, b, s, 12);
+ D_RC5_32(a, b, s, 10);
+ D_RC5_32(a, b, s, 8);
+ D_RC5_32(a, b, s, 6);
+ D_RC5_32(a, b, s, 4);
+ D_RC5_32(a, b, s, 2);
+ d[0] = a - s[0];
+ d[1] = b - s[1];
+}