Skip to content

Why am I getting a decryption error during encryption? #21709

Answered by jaraco
jaraco asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out. I added some troubleshooting to check the value of ctx.encrypt and it was 0, even immediately after the initialization.

The issue is in the FFI spec for EVP_CipherInit_ex:

lib.EVP_CipherInit_ex.argtypes = (
    ctypes.POINTER(Cipher),
    ctypes.POINTER(CipherType),
    ctypes.c_void_p,
    ctypes.c_char_p,
    ctypes.c_char_p,
)

The spec is missing the last parameter for enc.

And for some reason that I don't yet understand, on Python for ARM for macOS only, ctypes either ignores the encrypt parameter or casts True to 0.

Adding ctypes.c_int to the signature resolves the issue.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jaraco
Comment options

Answer selected by jaraco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant