forked from mikeboers/PyTomCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpkcs1.pyx
More file actions
31 lines (24 loc) · 892 Bytes
/
Copy pathpkcs1.pyx
File metadata and controls
31 lines (24 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from tomcrypt._core cimport *
from tomcrypt.prng cimport PRNG, conform_prng
from tomcrypt import Error
cpdef pkcs1_v1_5_encode(message, block_type, int modulus_bitlen, prng=None):
cdef ByteSource c_msg = bytesource(message)
if block_type in (LTC_PKCS_1_EME, 'eme', 'encrypt', 'decrypt'):
block_type = LTC_PKCS_1_EME
elif block_type in (LTC_PKCS_1_EMSA, 'emsa', 'sign', 'verify'):
block_type = LTC_PKCS_1_EMSA
else:
raise Error('unknown block_type %r' % block_type)
cdef PRNG c_prng = conform_prng(prng)
cdef unsigned long outlen = modulus_bitlen / 8 + 1
out = PyBytes_FromStringAndSize(NULL, outlen)
check_for_error(c_pkcs1_v1_5_encode(
c_msg.ptr, c_msg.length,
block_type,
modulus_bitlen,
&c_prng.state,
c_prng.idx,
out,
&outlen
))
return out[:outlen]