|
@@ -957,8 +957,6 @@ static const struct myoption admin_long_options[] = {
|
|
{ NULL, no_argument, NULL, 0 }
|
|
{ NULL, no_argument, NULL, 0 }
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-struct ctr_state state;
|
|
|
|
int init_ctr(struct ctr_state *state, const unsigned char iv[8]){
|
|
int init_ctr(struct ctr_state *state, const unsigned char iv[8]){
|
|
state->num = 0;
|
|
state->num = 0;
|
|
memset(state->ecount, 0, 16);
|
|
memset(state->ecount, 0, 16);
|
|
@@ -966,6 +964,7 @@ int init_ctr(struct ctr_state *state, const unsigned char iv[8]){
|
|
memcpy(state->ivec, iv, 8);
|
|
memcpy(state->ivec, iv, 8);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
unsigned char *base64encode (const void *b64_encode_this, int encode_this_many_bytes){
|
|
unsigned char *base64encode (const void *b64_encode_this, int encode_this_many_bytes){
|
|
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
|
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
|
BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data.
|
|
BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data.
|
|
@@ -974,9 +973,9 @@ unsigned char *base64encode (const void *b64_encode_this, int encode_this_many_b
|
|
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-sink BIO chain.
|
|
BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-sink BIO chain.
|
|
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //No newlines every 64 characters or less.
|
|
BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //No newlines every 64 characters or less.
|
|
BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); //Records base64 encoded data.
|
|
BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); //Records base64 encoded data.
|
|
- BIO_flush(b64_bio); //Flush data. Necessary for b64 encoding, because of pad characters.
|
|
|
|
|
|
+ (void)BIO_flush(b64_bio); //Flush data. Necessary for b64 encoding, because of pad characters.
|
|
BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr); //Store address of mem_bio's memory structure.
|
|
BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr); //Store address of mem_bio's memory structure.
|
|
- BIO_set_close(mem_bio, BIO_NOCLOSE); //Permit access to mem_ptr after BIOs are destroyed.
|
|
|
|
|
|
+ (void)BIO_set_close(mem_bio, BIO_NOCLOSE); //Permit access to mem_ptr after BIOs are destroyed.
|
|
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
|
BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one).
|
|
BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); //Makes space for end null.
|
|
BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); //Makes space for end null.
|
|
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; //Adds null-terminator to tail.
|
|
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; //Adds null-terminator to tail.
|
|
@@ -992,6 +991,7 @@ void encrypt_aes_128(unsigned char* in, const unsigned char* mykey){
|
|
AES_set_encrypt_key(mykey, 128, &key);
|
|
AES_set_encrypt_key(mykey, 128, &key);
|
|
char total[256];
|
|
char total[256];
|
|
int size=0;
|
|
int size=0;
|
|
|
|
+ struct ctr_state state;
|
|
init_ctr(&state, iv);
|
|
init_ctr(&state, iv);
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
|
@@ -1045,7 +1045,7 @@ void generate_aes_128_key(char* filePath, unsigned char* returnedKey){
|
|
|
|
|
|
unsigned char *base64decode (const void *b64_decode_this, int decode_this_many_bytes){
|
|
unsigned char *base64decode (const void *b64_decode_this, int decode_this_many_bytes){
|
|
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
|
BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO.
|
|
- unsigned char *base64_decoded = calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
|
|
|
|
|
|
+ unsigned char *base64_decoded = (unsigned char*)calloc( (decode_this_many_bytes*3)/4+1, sizeof(char) ); //+1 = null.
|
|
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
|
|
b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO.
|
|
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory source BIO.
|
|
mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory source BIO.
|
|
BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); //Base64 data saved in source.
|
|
BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes); //Base64 data saved in source.
|
|
@@ -1080,6 +1080,7 @@ void decrypt_aes_128(char* in, const unsigned char* mykey){
|
|
int bytes_to_decode = strlen(in);
|
|
int bytes_to_decode = strlen(in);
|
|
unsigned char *encryptedText = base64decode(in, bytes_to_decode);
|
|
unsigned char *encryptedText = base64decode(in, bytes_to_decode);
|
|
char last[1024]="";
|
|
char last[1024]="";
|
|
|
|
+ struct ctr_state state;
|
|
init_ctr(&state, iv);
|
|
init_ctr(&state, iv);
|
|
memset(outdata,'\0', sizeof(outdata));
|
|
memset(outdata,'\0', sizeof(outdata));
|
|
|
|
|