Skip to content

AES GCM mode with SoftHSM2 fails to decrypt more than one block #160

@tstiemerling

Description

@tstiemerling

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;

}

Discussed in #159

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions