diff options
| author | beck <> | 2023-07-07 12:51:58 +0000 |
|---|---|---|
| committer | beck <> | 2023-07-07 12:51:58 +0000 |
| commit | 703d7f5fc9c68d0fd6c3b13c056d53c072366a79 (patch) | |
| tree | 4959b4936ded67fb6b286e463fbc27eee245ce20 /src/lib/libcrypto/idea/i_cbc.c | |
| parent | e7aea55ea47e895c51a84147a1cb230cf7a29b33 (diff) | |
| download | openbsd-703d7f5fc9c68d0fd6c3b13c056d53c072366a79.tar.gz openbsd-703d7f5fc9c68d0fd6c3b13c056d53c072366a79.tar.bz2 openbsd-703d7f5fc9c68d0fd6c3b13c056d53c072366a79.zip | |
Hit idea with the loving mallet of knfmt
ok knfmt
Diffstat (limited to 'src/lib/libcrypto/idea/i_cbc.c')
| -rw-r--r-- | src/lib/libcrypto/idea/i_cbc.c | 186 |
1 files changed, 96 insertions, 90 deletions
diff --git a/src/lib/libcrypto/idea/i_cbc.c b/src/lib/libcrypto/idea/i_cbc.c index e382a0a69e..a9de41d647 100644 --- a/src/lib/libcrypto/idea/i_cbc.c +++ b/src/lib/libcrypto/idea/i_cbc.c | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | /* $OpenBSD: i_cbc.c,v 1.4 2022/11/26 16:08:53 tb Exp $ */ | 1 | /* $OpenBSD: i_cbc.c,v 1.5 2023/07/07 12:51:58 beck Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -59,91 +59,96 @@ | |||
| 59 | #include <openssl/idea.h> | 59 | #include <openssl/idea.h> |
| 60 | #include "idea_local.h" | 60 | #include "idea_local.h" |
| 61 | 61 | ||
| 62 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | 62 | void |
| 63 | IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int encrypt) | 63 | idea_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, |
| 64 | { | 64 | IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int encrypt) |
| 65 | unsigned long tin0,tin1; | 65 | { |
| 66 | unsigned long tout0,tout1,xor0,xor1; | 66 | unsigned long tin0, tin1; |
| 67 | long l=length; | 67 | unsigned long tout0, tout1, xor0, xor1; |
| 68 | long l = length; | ||
| 68 | unsigned long tin[2]; | 69 | unsigned long tin[2]; |
| 69 | 70 | ||
| 70 | if (encrypt) | 71 | if (encrypt) { |
| 72 | n2l(iv, tout0); | ||
| 73 | n2l(iv, tout1); | ||
| 74 | iv -= 8; | ||
| 75 | for (l -= 8; l >= 0; l -= 8) | ||
| 71 | { | 76 | { |
| 72 | n2l(iv,tout0); | 77 | n2l(in, tin0); |
| 73 | n2l(iv,tout1); | 78 | n2l(in, tin1); |
| 74 | iv-=8; | 79 | tin0 ^= tout0; |
| 75 | for (l-=8; l>=0; l-=8) | 80 | tin1 ^= tout1; |
| 76 | { | 81 | tin[0] = tin0; |
| 77 | n2l(in,tin0); | 82 | tin[1] = tin1; |
| 78 | n2l(in,tin1); | 83 | idea_encrypt(tin, ks); |
| 79 | tin0^=tout0; | 84 | tout0 = tin[0]; |
| 80 | tin1^=tout1; | 85 | l2n(tout0, out); |
| 81 | tin[0]=tin0; | 86 | tout1 = tin[1]; |
| 82 | tin[1]=tin1; | 87 | l2n(tout1, out); |
| 83 | idea_encrypt(tin,ks); | 88 | } |
| 84 | tout0=tin[0]; l2n(tout0,out); | 89 | if (l != -8) { |
| 85 | tout1=tin[1]; l2n(tout1,out); | 90 | n2ln(in, tin0, tin1, l + 8); |
| 86 | } | 91 | tin0 ^= tout0; |
| 87 | if (l != -8) | 92 | tin1 ^= tout1; |
| 88 | { | 93 | tin[0] = tin0; |
| 89 | n2ln(in,tin0,tin1,l+8); | 94 | tin[1] = tin1; |
| 90 | tin0^=tout0; | 95 | idea_encrypt(tin, ks); |
| 91 | tin1^=tout1; | 96 | tout0 = tin[0]; |
| 92 | tin[0]=tin0; | 97 | l2n(tout0, out); |
| 93 | tin[1]=tin1; | 98 | tout1 = tin[1]; |
| 94 | idea_encrypt(tin,ks); | 99 | l2n(tout1, out); |
| 95 | tout0=tin[0]; l2n(tout0,out); | ||
| 96 | tout1=tin[1]; l2n(tout1,out); | ||
| 97 | } | ||
| 98 | l2n(tout0,iv); | ||
| 99 | l2n(tout1,iv); | ||
| 100 | } | 100 | } |
| 101 | else | 101 | l2n(tout0, iv); |
| 102 | l2n(tout1, iv); | ||
| 103 | } else { | ||
| 104 | n2l(iv, xor0); | ||
| 105 | n2l(iv, xor1); | ||
| 106 | iv -= 8; | ||
| 107 | for (l -= 8; l >= 0; l -= 8) | ||
| 102 | { | 108 | { |
| 103 | n2l(iv,xor0); | 109 | n2l(in, tin0); |
| 104 | n2l(iv,xor1); | 110 | tin[0] = tin0; |
| 105 | iv-=8; | 111 | n2l(in, tin1); |
| 106 | for (l-=8; l>=0; l-=8) | 112 | tin[1] = tin1; |
| 107 | { | 113 | idea_encrypt(tin, ks); |
| 108 | n2l(in,tin0); tin[0]=tin0; | 114 | tout0 = tin[0] ^ xor0; |
| 109 | n2l(in,tin1); tin[1]=tin1; | 115 | tout1 = tin[1] ^ xor1; |
| 110 | idea_encrypt(tin,ks); | 116 | l2n(tout0, out); |
| 111 | tout0=tin[0]^xor0; | 117 | l2n(tout1, out); |
| 112 | tout1=tin[1]^xor1; | 118 | xor0 = tin0; |
| 113 | l2n(tout0,out); | 119 | xor1 = tin1; |
| 114 | l2n(tout1,out); | ||
| 115 | xor0=tin0; | ||
| 116 | xor1=tin1; | ||
| 117 | } | ||
| 118 | if (l != -8) | ||
| 119 | { | ||
| 120 | n2l(in,tin0); tin[0]=tin0; | ||
| 121 | n2l(in,tin1); tin[1]=tin1; | ||
| 122 | idea_encrypt(tin,ks); | ||
| 123 | tout0=tin[0]^xor0; | ||
| 124 | tout1=tin[1]^xor1; | ||
| 125 | l2nn(tout0,tout1,out,l+8); | ||
| 126 | xor0=tin0; | ||
| 127 | xor1=tin1; | ||
| 128 | } | ||
| 129 | l2n(xor0,iv); | ||
| 130 | l2n(xor1,iv); | ||
| 131 | } | 120 | } |
| 132 | tin0=tin1=tout0=tout1=xor0=xor1=0; | 121 | if (l != -8) { |
| 133 | tin[0]=tin[1]=0; | 122 | n2l(in, tin0); |
| 123 | tin[0] = tin0; | ||
| 124 | n2l(in, tin1); | ||
| 125 | tin[1] = tin1; | ||
| 126 | idea_encrypt(tin, ks); | ||
| 127 | tout0 = tin[0] ^ xor0; | ||
| 128 | tout1 = tin[1] ^ xor1; | ||
| 129 | l2nn(tout0, tout1, out, l + 8); | ||
| 130 | xor0 = tin0; | ||
| 131 | xor1 = tin1; | ||
| 132 | } | ||
| 133 | l2n(xor0, iv); | ||
| 134 | l2n(xor1, iv); | ||
| 134 | } | 135 | } |
| 136 | tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | ||
| 137 | tin[0] = tin[1] = 0; | ||
| 138 | } | ||
| 135 | 139 | ||
| 136 | void idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key) | 140 | void |
| 137 | { | 141 | idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key) |
| 142 | { | ||
| 138 | IDEA_INT *p; | 143 | IDEA_INT *p; |
| 139 | unsigned long x1,x2,x3,x4,t0,t1,ul; | 144 | unsigned long x1, x2, x3, x4, t0, t1, ul; |
| 140 | 145 | ||
| 141 | x2=d[0]; | 146 | x2 = d[0]; |
| 142 | x1=(x2>>16); | 147 | x1 = (x2 >> 16); |
| 143 | x4=d[1]; | 148 | x4 = d[1]; |
| 144 | x3=(x4>>16); | 149 | x3 = (x4 >> 16); |
| 145 | 150 | ||
| 146 | p= &(key->data[0][0]); | 151 | p = &(key->data[0][0]); |
| 147 | 152 | ||
| 148 | E_IDEA(0); | 153 | E_IDEA(0); |
| 149 | E_IDEA(1); | 154 | E_IDEA(1); |
| @@ -154,15 +159,16 @@ void idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key) | |||
| 154 | E_IDEA(6); | 159 | E_IDEA(6); |
| 155 | E_IDEA(7); | 160 | E_IDEA(7); |
| 156 | 161 | ||
| 157 | x1&=0xffff; | 162 | x1 &= 0xffff; |
| 158 | idea_mul(x1,x1,*p,ul); p++; | 163 | idea_mul(x1, x1, *p, ul); |
| 164 | p++; | ||
| 159 | 165 | ||
| 160 | t0= x3+ *(p++); | 166 | t0 = x3 + *(p++); |
| 161 | t1= x2+ *(p++); | 167 | t1 = x2 + *(p++); |
| 162 | 168 | ||
| 163 | x4&=0xffff; | 169 | x4 &= 0xffff; |
| 164 | idea_mul(x4,x4,*p,ul); | 170 | idea_mul(x4, x4, *p, ul); |
| 165 | 171 | ||
| 166 | d[0]=(t0&0xffff)|((x1&0xffff)<<16); | 172 | d[0] = (t0 & 0xffff)|((x1 & 0xffff) << 16); |
| 167 | d[1]=(x4&0xffff)|((t1&0xffff)<<16); | 173 | d[1] = (x4 & 0xffff)|((t1 & 0xffff) << 16); |
| 168 | } | 174 | } |
