gs: replace openssl aes implementation with ape/libsec
This commit is contained in:
parent
464763202b
commit
8f4db30e78
3 changed files with 11 additions and 9 deletions
|
@ -64,8 +64,7 @@ BIN=/$objtype/bin
|
|||
TARG=gs
|
||||
OFILES=\
|
||||
obj/gs.$O\
|
||||
`{sed 's#^./obj/(.*)\.o .*#obj/\1.$O#' src/ld.tr >[2] /dev/null | sort} \
|
||||
/$objtype/lib/ape/libcrypto.a
|
||||
`{sed 's#^./obj/(.*)\.o .*#obj/\1.$O#' src/ld.tr >[2] /dev/null | sort}
|
||||
|
||||
# The first driver is the default.
|
||||
DRIVERS=\
|
||||
|
|
|
@ -102,19 +102,20 @@ s_aes_process(stream_state * ss, stream_cursor_read * pr,
|
|||
if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH)
|
||||
return ERRC;
|
||||
if (!state->initialized) {
|
||||
memset(&state->aes, 0, sizeof(state->aes));
|
||||
AES_set_decrypt_key(state->key, state->keylength*8, &state->aes);
|
||||
if (in_size < 16) return 0; /* get more data */
|
||||
|
||||
/* read the initialization vector from the first 16 bytes */
|
||||
if (in_size < 16) return 0; /* get more data */
|
||||
memcpy(state->iv, pr->ptr + 1, 16);
|
||||
state->initialized = 1;
|
||||
pr->ptr += 16;
|
||||
|
||||
setupAESstate(&state->aes, state->key, state->keylength, state->iv);
|
||||
state->initialized = 1;
|
||||
}
|
||||
|
||||
/* decrypt available blocks */
|
||||
while (pr->ptr + 16 <= limit) {
|
||||
AES_cbc_encrypt(pr->ptr + 1, temp, 16, &state->aes, state->iv, AES_DECRYPT);
|
||||
memcpy(temp, pr->ptr + 1, 16);
|
||||
aesCBCdecrypt(temp, 16, &state->aes);
|
||||
pr->ptr += 16;
|
||||
if (last && pr->ptr == pr->limit) {
|
||||
/* we're on the last block; unpad if necessary */
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
# define saes_INCLUDED
|
||||
|
||||
#include "scommon.h"
|
||||
#include <openssl/aes.h>
|
||||
|
||||
#define _PLAN9_SOURCE
|
||||
#include <libsec.h>
|
||||
|
||||
/* maximum supported key length in bytes */
|
||||
#define SAES_MAX_KEYLENGTH 32
|
||||
|
@ -36,7 +38,7 @@ struct stream_aes_state_s
|
|||
unsigned char iv[16]; /* CBC initialization vector */
|
||||
int initialized; /* whether we're set up */
|
||||
int use_padding; /* are we using RFC 1423-style padding? */
|
||||
AES_KEY aes;
|
||||
AESstate aes;
|
||||
};
|
||||
|
||||
#ifndef stream_aes_state_DEFINED
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue