Skip to content

added aes-gcm - #2165

Open
bmatusiak wants to merge 7 commits into
espruino:masterfrom
bmatusiak:CRYPTO_AES-GCM
Open

added aes-gcm#2165
bmatusiak wants to merge 7 commits into
espruino:masterfrom
bmatusiak:CRYPTO_AES-GCM

Conversation

@bmatusiak

@bmatusiak bmatusiak commented Mar 4, 2022

Copy link
Copy Markdown

this need testing,

but here in a test scripts for espruino and browser
https://gist.github.com/bmatusiak/c4517056a93f96ea904e85b7f5c0ddb5

@bmatusiak

Copy link
Copy Markdown
Author

yea there still need work to be done

@gfwilliams

Copy link
Copy Markdown
Member

yea there still need work to be done

Thanks! So where are we at with this? Does it build and work ok for those test scripts?

@bmatusiak

Copy link
Copy Markdown
Author

the problem im running into is,

the encrypted data being generated from mbedtls is not verifyable (it can decrypt it, but the gcm tag is invalid causing a failed decryption )..

but encrypted data from webcrypt/browser is verifyable in mbed tls

@bmatusiak

Copy link
Copy Markdown
Author

SIDE note, so instead of hunting down the issue on that yesterday.. i coded up ECDH

https://gist.github.com/bmatusiak/a1ac4b31cf5fd4c2c4ac2a9b0fd377ff

@bmatusiak

Copy link
Copy Markdown
Author

ok i fixed gcm encrypt auth tag
all thats left is importing "additional data"

@bmatusiak

Copy link
Copy Markdown
Author

I changed IV to be a variable length, 16 = {0} is default(for all modes)

added additionalData and tagLength options

var opts = {
        iv: new Uint8Array(16),
        mode: 'GCM',
        additionalData: new Uint8Array( ), //GCM max length AddData is 18446744073709551615 
        tagLength:128, // in bit size (128=16bytes)
    };

jsvIterateCallbackToBytes(ivVar, iv, sizeof(iv));
if (ivVar && !jsvIsUndefined(ivVar)) {
iv_size = (size_t)jsvGetLength(ivVar);
jsvIterateCallbackToBytes(ivVar, &iv_bytes, (unsigned int)iv_size);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's taken so long to look into this - but this one in particular looks broken.

iv_bytes is never set, so at this point jsvIterateCallbackToBytes will write into a random area of memory! It's possible that by using &iv_bytes you're just writing onto the stack, but there's definitely an issue here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants