From 06919e91eb8f60c7205b51cc3dac31a35e34430c Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Fri, 21 Mar 2014 12:27:12 -0400 Subject: padding and constant time also need the cffi modulename fix --- cryptography/hazmat/primitives/constant_time.py | 20 ++++++++++++++------ cryptography/hazmat/primitives/padding.py | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cryptography/hazmat/primitives/constant_time.py b/cryptography/hazmat/primitives/constant_time.py index e88a0d95..e0e9aa37 100644 --- a/cryptography/hazmat/primitives/constant_time.py +++ b/cryptography/hazmat/primitives/constant_time.py @@ -13,18 +13,20 @@ from __future__ import absolute_import, division, print_function +import sys + import cffi import six +from cryptography.hazmat.bindings.utils import _create_modulename -_ffi = cffi.FFI() -_ffi.cdef(""" +TYPES = """ uint8_t Cryptography_constant_time_bytes_eq(uint8_t *, size_t, uint8_t *, size_t); -""") -_lib = _ffi.verify( - """ +""" + +FUNCTIONS = """ uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a, uint8_t *b, size_t len_b) { size_t i = 0; @@ -43,7 +45,13 @@ uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a, /* Now check the low bit to see if it's set */ return (mismatch & 1) == 0; } -""", +""" + +_ffi = cffi.FFI() +_ffi.cdef(TYPES) +_lib = _ffi.verify( + source=FUNCTIONS, + modulename=_create_modulename([TYPES], FUNCTIONS, sys.version), ext_package="cryptography", ) diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py index bf634a65..d78c6a5b 100644 --- a/cryptography/hazmat/primitives/padding.py +++ b/cryptography/hazmat/primitives/padding.py @@ -13,20 +13,22 @@ from __future__ import absolute_import, division, print_function +import sys + import cffi import six from cryptography import utils +from cryptography.hazmat.bindings.utils import _create_modulename from cryptography.hazmat.primitives import interfaces -_ffi = cffi.FFI() -_ffi.cdef(""" +TYPES = """ uint8_t Cryptography_check_pkcs7_padding(const uint8_t *, uint8_t); -""") -_lib = _ffi.verify( - """ +""" + +FUNCTIONS = """ /* Returns the value of the input with the most-significant-bit copied to all of the bits. */ static uint8_t Cryptography_DUPLICATE_MSB_TO_ALL(uint8_t a) { @@ -62,7 +64,13 @@ uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data, /* Now check the low bit to see if it's set */ return (mismatch & 1) == 0; } -""", +""" + +_ffi = cffi.FFI() +_ffi.cdef(TYPES) +_lib = _ffi.verify( + source=FUNCTIONS, + modulename=_create_modulename([TYPES], FUNCTIONS, sys.version), ext_package="cryptography", ) -- cgit v1.2.3