ref: 8f4db30e7865232f9179f5850fe0e1ca759302cc
parent: 464763202be7bdafa703c8c2ecfe1f4a5142f26f
author: cinap_lenrek <[email protected]>
date: Mon Apr 11 16:27:50 EDT 2016
gs: replace openssl aes implementation with ape/libsec
--- a/sys/src/cmd/gs/mkfile
+++ b/sys/src/cmd/gs/mkfile
@@ -64,8 +64,7 @@
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=\
--- a/sys/src/cmd/gs/src/saes.c
+++ b/sys/src/cmd/gs/src/saes.c
@@ -102,19 +102,20 @@
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 */
--- a/sys/src/cmd/gs/src/saes.h
+++ b/sys/src/cmd/gs/src/saes.h
@@ -21,8 +21,10 @@
# 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 @@
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