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