ref: 12bb7bcfff4db1b122c4643859f3d4f1420fba38
parent: e9c9ea4235697b84d0745c3d56b476230bad27bb
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Apr 28 22:58:10 EDT 2015
libsec: remove aesCTRencrypt()/aesCTRdecrypt() (thanks mischief and qrstuv) as mischief and qrstuv point out, these functions are not very usefull and are even implemented wrong (incrementCTR()), so deleting the code.
--- a/sys/include/libsec.h
+++ b/sys/include/libsec.h
@@ -23,7 +23,6 @@
ulong setup;
int rounds;
int keybytes;
- uint ctrsz;
uchar key[AESmaxkey]; /* unexpanded key */
ulong ekey[4*(AESmaxrounds + 1)]; /* encryption key */
ulong dkey[4*(AESmaxrounds + 1)]; /* decryption key */
@@ -38,8 +37,6 @@
void setupAESstate(AESstate *s, uchar key[], int keybytes, uchar *ivec);
void aesCBCencrypt(uchar *p, int len, AESstate *s);
void aesCBCdecrypt(uchar *p, int len, AESstate *s);
-void aesCTRdecrypt(uchar *p, int len, AESstate *s);
-void aesCTRencrypt(uchar *p, int len, AESstate *s);
void setupAESXCBCstate(AESstate *s);
uchar* aesXCBCmac(uchar *p, int len, AESstate *s);
--- a/sys/man/2/aes
+++ b/sys/man/2/aes
@@ -1,6 +1,6 @@
.TH AES 2
.SH NAME
-setupAESstate, aesCBCencrypt, aesCBCdecrypt, aesCTRencrypt, aesCTRdecrypt, setupAESXCBCstate, aesXCBCmac - advanced encryption standard (rijndael)
+setupAESstate, aesCBCencrypt, aesCBCdecrypt, setupAESXCBCstate, aesXCBCmac - advanced encryption standard (rijndael)
.SH SYNOPSIS
.B #include <u.h>
.br
@@ -28,12 +28,6 @@
void aesCBCdecrypt(uchar *p, int len, AESstate *s)
.PP
.B
-void aesCTRencrypt(uchar *p, int len, AESstate *s)
-.PP
-.B
-void aesCTRdecrypt(uchar *p, int len, AESstate *s)
-.PP
-.B
void setupAESXCBCstate(AESstate *s)
.PP
.B
@@ -52,11 +46,6 @@
and
.I aesCBCdecrypt
implement cipher-block-chaining encryption.
-.I AesCTRencrypt
-and
-.I aesCTRdecrypt
-implement counter mode, per RFC 3686;
-they are identical operations.
.I setupAESXCBCstate
and
.I aesXCBCmac
@@ -93,8 +82,6 @@
The functions
.IR aes_encrypt ,
.IR aes_decrypt ,
-.IR aesCTRencrypt ,
-.IR aesCTRdecrypt ,
.IR setupAESXCBCstate ,
and
.IR aesXCBCmac
--- a/sys/src/libsec/port/aes.c
+++ b/sys/src/libsec/port/aes.c
@@ -220,61 +220,6 @@
}
}
-/*
- * AES-CTR mode, per rfc3686.
- * CTRs could be precalculated for efficiency
- * and there would also be less back and forth mp
- */
-
-static void
-incrementCTR(uchar *p, uint ctrsz)
-{
- int len;
- uchar *ctr;
- mpint *mpctr, *mpctrsz;
-
- ctr = p + AESbsize - ctrsz;
- mpctr = betomp(ctr, ctrsz, nil);
- mpctrsz = itomp(1 << (ctrsz*8), nil);
- mpadd(mpctr, mpone, mpctr);
- mpmod(mpctr, mpctrsz, mpctr);
- len = mptobe(mpctr, ctr, ctrsz, nil);
- assert(len == ctrsz);
- mpfree(mpctrsz);
- mpfree(mpctr);
-}
-
-void
-aesCTRencrypt(uchar *p, int len, AESstate *s)
-{
- uchar q[AESbsize];
- uchar *ip, *eip, *ctr;
-
- ctr = s->ivec;
- for(; len >= AESbsize; len -= AESbsize){
- ip = q;
- aes_encrypt(s->ekey, s->rounds, ctr, q);
- for(eip = p + AESbsize; p < eip; )
- *p++ ^= *ip++;
- incrementCTR(ctr, s->ctrsz);
- }
-
- if(len > 0){
- ip = q;
- aes_encrypt(s->ekey, s->rounds, ctr, q);
- for(eip = p + len; p < eip; )
- *p++ ^= *ip++;
- incrementCTR(ctr, s->ctrsz);
- }
-}
-
-void
-aesCTRdecrypt(uchar *p, int len, AESstate *s)
-{
- aesCTRencrypt(p, len, s);
-}
-
-
/* taken from sha1; TODO: verify suitability (esp. byte order) for aes */
/*
* encodes input (ulong) into output (uchar). Assumes len is