mko-x/SharedAES-GCM

Simple example

JlnWntr opened this issue · 4 comments

I'm testing this:

unsigned char output[] = "0000000000000000";
const unsigned char input[] = "0123456789ABCDEF";
int input_length = 16;
const unsigned char key[] = "0123456789ABCDEF";
const size_t key_len = 16;
const unsigned char iv[] = "1111111111111111";
const size_t iv_len = 16;

if(aes_gcm_encrypt(output, input, input_length, key, key_len, iv, iv_len) == 0)
        printf("Encryption successssful! \n");

But I keep getting an invalid read of size 4.

==5723== at 0x402279: aes_cipher (aes.c:389)
==5723== by 0x400CFA: gcm_setkey (gcm.c:190)
==5723== by 0x4006BA: aes_gcm_encrypt (aes-gcm.c:20)
==5723== by 0x40097A: main (aes-gcm.c:60)
==5723== Address 0x0 is not stack'd, malloc'd or (recently) free'd

I guess I'm using it the wrong way. Can you please provide a simple usage example for your aes-gcm implementation? It really looks promising.

mko-x commented

You are calling the C reference implementation itself - no need to use this objective-c wrapper therefore.

Find samples to call at https://github.com/michaeljclark/aes-gcm

Thanks for your fine work on this. I too could use some examples on how to use this though.

It's a little unclear what you meant by "Find samples to call at: https://github.com/michaeljclark/aes-gcm". What files were you referring to?

Can you maybe provide a simple example of how to encrypt and decrypt a file?

Many thanks!

mko-x commented

Hey @stevensam

You can find sample calls to the methods in the file at

https://github.com/michaeljclark/aes-gcm/blob/master/src/aes-gcm-test.c

In cryptography, Galois/Counter Mode (GCM) is a mode of operation for symmetric-key cryptographic block ciphers widely adopted for its performance. GCM throughput rates for state-of-the-art, high-speed communication channels can be achieved with inexpensive hardware resources.
Source: https://link.springer.com/chapter/10.1007%2F978-3-540-74735-2_16

This cipher is not made for en-/decrypting a file but, you would have to provide logic to read the file and parse it through aes_gcm.

Add the example given above you would need to fill the variable

t3_plainwith your desired data in hex.

Thanks for the clarification on the sample file, and the hint about how to go about adapting it for file encryption. Much appreciate!