-
-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Swift] how can I use signal_aes256_gcm_decryption_new in ffi #477
Comments
These are general-purpose AES-256-GCM APIs that we haven't finished hooking up to Swift; though they should work as C functions, the C interface is considered an implementation detail and may change from release to release without notice. (But you probably already know that.) The That said, the usage from C would be something like SignalFfiError *error;
SignalAes256GcmDecryption *decrypt;
error = signal_aes256_gcm_decryption_new(&decrypt, key, nonce, associatedDataFromWhenYouEncrypted);
if (error) { return NULL; }
error = signal_aes256_gcm_decryption_update(decrypt, message, 0, message.length); // modifies 'message'
if (error) { return NULL; }
bool valid = false;
error = signal_aes256_gcm_decryption_verify_tag(&valid, decrypt, tag); // VERY IMPORTANT
if (error || !valid) { return NULL; }
error = signal_aes256_gcm_decryption_destroy(decrypt);
if (error) { /* log, maybe? */ }
char *result = malloc(message.length);
memcpy(result, message.buffer, message.length);
return result; I'll note that this is a relatively "unsafe" implementation of AES-GCM, because it requires you to remember to call |
thank you for your reply! Q1. in Swift, is "Aes256GcmSiv class" the higher-level operations for that? and from your sample code I made the below code in Swift. Q2. how can I make decrypt variable below code?
} thank you again for your reply! |
hello.
I am struggling to use libSignal for Swift.
after x3dh, now I get the key for encrypt and decrypt.
So I am ready kdf message key, nonce, tag, and aead.
For encrypt and decrypt, we decided to use
public static native void Aes256GcmDecryption_Update(long gcm, byte[] data, int offset, int length);
public static native void Aes256GcmEncryption_Update(long gcm, byte[] data, int offset, int length);
in java.
Q1. is signal_aes256_gcm_decryption_new in ffi function same as above java function?
SignalFfiError *signal_aes256_gcm_decryption_new(SignalAes256GcmDecryption **out,
SignalBorrowedBuffer key,
SignalBorrowedBuffer nonce,
SignalBorrowedBuffer associated_data);
SignalFfiError *signal_aes256_gcm_decryption_update(SignalAes256GcmDecryption *gcm,
SignalBorrowedMutableBuffer data,
uint32_t offset,
uint32_t length);
SignalFfiError *signal_aes256_gcm_decryption_verify_tag(bool *out,
SignalAes256GcmDecryption *gcm,
SignalBorrowedBuffer tag);
if so, could you give me a sample source how to use the function?
The text was updated successfully, but these errors were encountered: