Hi, the SoftHSM2 implementation of GCM decrypt does not return any data until you call C_DecryptFinal (not sure if other P11 implementations are the same), so the final() method in decipher.ts is failing since it only allocates one block for the plaintext, but SoftHSM2 is expecting a buffer equal to the plaintext length.
public final(): Buffer {
const dec = Buffer.alloc(this.blockSize);
const res = this.lib.C_DecryptFinal(this.session.handle, dec);
return res;
Originally posted by **tstiemerling** April 3, 2024
Are there any examples of using AES GCM mode? I am trying to use graphene with SoftHSM2 (windows build) and I getting CKR_BUFFER_TOO_SMALL returned on decrypt (unit test). The offending SoftHSM code seems to be here:
c:\build\src\softhsm-2.5.0-x64\src\lib\softhsm.cpp(3256): Output buffer too short ulEncryptedDataLen: 0x10 output buffer size: 0x20 blockSize: 0x10 remainingSize: 0x100 maxSize: 0x110
Hi, the SoftHSM2 implementation of GCM decrypt does not return any data until you call C_DecryptFinal (not sure if other P11 implementations are the same), so the final() method in decipher.ts is failing since it only allocates one block for the plaintext, but SoftHSM2 is expecting a buffer equal to the plaintext length.
public final(): Buffer { const dec = Buffer.alloc(this.blockSize);
}
Discussed in https://github.com/PeculiarVentures/graphene/discussions/159