[prev in list] [next in list] [prev in thread] [next in thread]
List: openbsd-tech
Subject: [PATCH 4/6] crypto: IDEA: convert to use new modes 64-bit helpers
From: Dmitry Baryshkov <dbaryshkov () gmail ! com>
Date: 2020-06-27 19:36:59
Message-ID: 20200627193701.139170-4-dbaryshkov () gmail ! com
[Download RAW message or body]
Convert IDEA cipher to use 64-bit modes helper functions.
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
src/lib/libcrypto/idea/i_cbc.c | 74 +++-----------------------------
src/lib/libcrypto/idea/i_cfb64.c | 57 ++----------------------
src/lib/libcrypto/idea/i_ofb64.c | 47 ++------------------
3 files changed, 13 insertions(+), 165 deletions(-)
diff --git a/src/lib/libcrypto/idea/i_cbc.c b/src/lib/libcrypto/idea/i_cbc.c
index 5bb9640c3403..556a4aa5cbf3 100644
--- a/src/lib/libcrypto/idea/i_cbc.c
+++ b/src/lib/libcrypto/idea/i_cbc.c
@@ -57,81 +57,17 @@
*/
#include <openssl/idea.h>
+#include <openssl/modes.h>
#include "idea_lcl.h"
void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int encrypt)
- {
- unsigned long tin0,tin1;
- unsigned long tout0,tout1,xor0,xor1;
- long l=length;
- unsigned long tin[2];
-
+{
if (encrypt)
- {
- n2l(iv,tout0);
- n2l(iv,tout1);
- iv-=8;
- for (l-=8; l>=0; l-=8)
- {
- n2l(in,tin0);
- n2l(in,tin1);
- tin0^=tout0;
- tin1^=tout1;
- tin[0]=tin0;
- tin[1]=tin1;
- idea_encrypt(tin,ks);
- tout0=tin[0]; l2n(tout0,out);
- tout1=tin[1]; l2n(tout1,out);
- }
- if (l != -8)
- {
- n2ln(in,tin0,tin1,l+8);
- tin0^=tout0;
- tin1^=tout1;
- tin[0]=tin0;
- tin[1]=tin1;
- idea_encrypt(tin,ks);
- tout0=tin[0]; l2n(tout0,out);
- tout1=tin[1]; l2n(tout1,out);
- }
- l2n(tout0,iv);
- l2n(tout1,iv);
- }
+ CRYPTO_cbc64_encrypt(in, out, length, ks, iv, (block64_f)idea_ecb_encrypt);
else
- {
- n2l(iv,xor0);
- n2l(iv,xor1);
- iv-=8;
- for (l-=8; l>=0; l-=8)
- {
- n2l(in,tin0); tin[0]=tin0;
- n2l(in,tin1); tin[1]=tin1;
- idea_encrypt(tin,ks);
- tout0=tin[0]^xor0;
- tout1=tin[1]^xor1;
- l2n(tout0,out);
- l2n(tout1,out);
- xor0=tin0;
- xor1=tin1;
- }
- if (l != -8)
- {
- n2l(in,tin0); tin[0]=tin0;
- n2l(in,tin1); tin[1]=tin1;
- idea_encrypt(tin,ks);
- tout0=tin[0]^xor0;
- tout1=tin[1]^xor1;
- l2nn(tout0,tout1,out,l+8);
- xor0=tin0;
- xor1=tin1;
- }
- l2n(xor0,iv);
- l2n(xor1,iv);
- }
- tin0=tin1=tout0=tout1=xor0=xor1=0;
- tin[0]=tin[1]=0;
- }
+ CRYPTO_cbc64_decrypt(in, out, length, ks, iv, (block64_f)idea_ecb_encrypt);
+}
void idea_encrypt(unsigned long *d, IDEA_KEY_SCHEDULE *key)
{
diff --git a/src/lib/libcrypto/idea/i_cfb64.c b/src/lib/libcrypto/idea/i_cfb64.c
index b979aaef8669..a74b50d82309 100644
--- a/src/lib/libcrypto/idea/i_cfb64.c
+++ b/src/lib/libcrypto/idea/i_cfb64.c
@@ -57,6 +57,7 @@
*/
#include <openssl/idea.h>
+#include <openssl/modes.h>
#include "idea_lcl.h"
/* The input and output encrypted as though 64bit cfb mode is being
@@ -67,56 +68,6 @@
void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
long length, IDEA_KEY_SCHEDULE *schedule,
unsigned char *ivec, int *num, int encrypt)
- {
- unsigned long v0,v1,t;
- int n= *num;
- long l=length;
- unsigned long ti[2];
- unsigned char *iv,c,cc;
-
- iv=(unsigned char *)ivec;
- if (encrypt)
- {
- while (l--)
- {
- if (n == 0)
- {
- n2l(iv,v0); ti[0]=v0;
- n2l(iv,v1); ti[1]=v1;
- idea_encrypt((unsigned long *)ti,schedule);
- iv=(unsigned char *)ivec;
- t=ti[0]; l2n(t,iv);
- t=ti[1]; l2n(t,iv);
- iv=(unsigned char *)ivec;
- }
- c= *(in++)^iv[n];
- *(out++)=c;
- iv[n]=c;
- n=(n+1)&0x07;
- }
- }
- else
- {
- while (l--)
- {
- if (n == 0)
- {
- n2l(iv,v0); ti[0]=v0;
- n2l(iv,v1); ti[1]=v1;
- idea_encrypt((unsigned long *)ti,schedule);
- iv=(unsigned char *)ivec;
- t=ti[0]; l2n(t,iv);
- t=ti[1]; l2n(t,iv);
- iv=(unsigned char *)ivec;
- }
- cc= *(in++);
- c=iv[n];
- iv[n]=cc;
- *(out++)=c^cc;
- n=(n+1)&0x07;
- }
- }
- v0=v1=ti[0]=ti[1]=t=c=cc=0;
- *num=n;
- }
-
+{
+ CRYPTO_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt, (block64_f)idea_ecb_encrypt);
+}
diff --git a/src/lib/libcrypto/idea/i_ofb64.c b/src/lib/libcrypto/idea/i_ofb64.c
index 376dad9f6d91..9775bc211595 100644
--- a/src/lib/libcrypto/idea/i_ofb64.c
+++ b/src/lib/libcrypto/idea/i_ofb64.c
@@ -57,6 +57,7 @@
*/
#include <openssl/idea.h>
+#include <openssl/modes.h>
#include "idea_lcl.h"
/* The input and output encrypted as though 64bit ofb mode is being
@@ -66,46 +67,6 @@
void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, IDEA_KEY_SCHEDULE *schedule,
unsigned char *ivec, int *num)
- {
- unsigned long v0,v1,t;
- int n= *num;
- long l=length;
- unsigned char d[8];
- char *dp;
- unsigned long ti[2];
- unsigned char *iv;
- int save=0;
-
- iv=(unsigned char *)ivec;
- n2l(iv,v0);
- n2l(iv,v1);
- ti[0]=v0;
- ti[1]=v1;
- dp=(char *)d;
- l2n(v0,dp);
- l2n(v1,dp);
- while (l--)
- {
- if (n == 0)
- {
- idea_encrypt((unsigned long *)ti,schedule);
- dp=(char *)d;
- t=ti[0]; l2n(t,dp);
- t=ti[1]; l2n(t,dp);
- save++;
- }
- *(out++)= *(in++)^d[n];
- n=(n+1)&0x07;
- }
- if (save)
- {
- v0=ti[0];
- v1=ti[1];
- iv=(unsigned char *)ivec;
- l2n(v0,iv);
- l2n(v1,iv);
- }
- t=v0=v1=ti[0]=ti[1]=0;
- *num=n;
- }
-
+{
+ CRYPTO_ofb64_encrypt(in, out, length, schedule, ivec, num, (block64_f)idea_ecb_encrypt);
+}
--
2.27.0
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic