mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-11 09:59:19 -04:00
add iv as optional encrypt() param
This commit is contained in:
parent
5287531130
commit
ef880de64c
1 changed files with 8 additions and 4 deletions
|
|
@ -224,12 +224,14 @@ cdef class AES256_CTR_HMAC_SHA256:
|
|||
EVP_CIPHER_CTX_free(self.ctx)
|
||||
HMAC_CTX_free(self.hmac_ctx)
|
||||
|
||||
def encrypt(self, data, header=b'', aad_offset=0):
|
||||
def encrypt(self, data, header=b'', aad_offset=0, iv=None):
|
||||
"""
|
||||
encrypt data, compute mac over aad + iv + cdata, prepend header.
|
||||
aad_offset is the offset into the header where aad starts.
|
||||
"""
|
||||
assert self.blocks == 0, 'set_iv needs to be called before encrypt'
|
||||
if iv is not None:
|
||||
self.set_iv(iv)
|
||||
assert self.blocks == 0, 'iv needs to be set before encrypt is called'
|
||||
cdef int ilen = len(data)
|
||||
cdef int hlen = len(header)
|
||||
cdef int aoffset = aad_offset
|
||||
|
|
@ -382,12 +384,14 @@ cdef class _AEAD_BASE:
|
|||
def __dealloc__(self):
|
||||
EVP_CIPHER_CTX_free(self.ctx)
|
||||
|
||||
def encrypt(self, data, header=b'', aad_offset=0):
|
||||
def encrypt(self, data, header=b'', aad_offset=0, iv=None):
|
||||
"""
|
||||
encrypt data, compute mac over aad + iv + cdata, prepend header.
|
||||
aad_offset is the offset into the header where aad starts.
|
||||
"""
|
||||
assert self.blocks == 0, 'set_iv needs to be called before encrypt'
|
||||
if iv is not None:
|
||||
self.set_iv(iv)
|
||||
assert self.blocks == 0, 'iv needs to be set before encrypt is called'
|
||||
cdef int ilen = len(data)
|
||||
cdef int hlen = len(header)
|
||||
cdef int aoffset = aad_offset
|
||||
|
|
|
|||
Loading…
Reference in a new issue