Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compatibility with OpenSSL 1.1.0 #399

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Dependencies
------------

````
apt install libssl-dev libacl1-dev
````

What is Attic?
--------------
Attic is a deduplicating backup program. The main goal of Attic is to provide
Expand Down
19 changes: 10 additions & 9 deletions attic/crypto.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ cdef extern from "openssl/evp.h":
pass
const EVP_MD *EVP_sha256()
const EVP_CIPHER *EVP_aes_256_ctr()
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a)
void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a)
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new()
const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *a)
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a)

int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
const unsigned char *key, const unsigned char *iv)
Expand Down Expand Up @@ -84,16 +85,16 @@ def get_random_bytes(n):
cdef class AES:
"""A thin wrapper around the OpenSSL EVP cipher API
"""
cdef EVP_CIPHER_CTX ctx
cdef EVP_CIPHER_CTX * ctx

def __cinit__(self, key, iv=None):
EVP_CIPHER_CTX_init(&self.ctx)
if not EVP_EncryptInit_ex(&self.ctx, EVP_aes_256_ctr(), NULL, NULL, NULL):
self.ctx = EVP_CIPHER_CTX_new();
if not EVP_EncryptInit_ex(self.ctx, EVP_aes_256_ctr(), NULL, NULL, NULL):
raise Exception('EVP_EncryptInit_ex failed')
self.reset(key, iv)

def __dealloc__(self):
EVP_CIPHER_CTX_cleanup(&self.ctx)
EVP_CIPHER_CTX_free(self.ctx)

def reset(self, key=None, iv=None):
cdef const unsigned char *key2 = NULL
Expand All @@ -102,12 +103,12 @@ cdef class AES:
key2 = key
if iv:
iv2 = iv
if not EVP_EncryptInit_ex(&self.ctx, NULL, NULL, key2, iv2):
if not EVP_EncryptInit_ex(self.ctx, NULL, NULL, key2, iv2):
raise Exception('EVP_EncryptInit_ex failed')

@property
def iv(self):
return self.ctx.iv[:16]
return EVP_CIPHER_CTX_iv(self.ctx)[:16]

def encrypt(self, data):
cdef int inl = len(data)
Expand All @@ -116,7 +117,7 @@ cdef class AES:
if not out:
raise MemoryError
try:
if not EVP_EncryptUpdate(&self.ctx, out, &outl, data, inl):
if not EVP_EncryptUpdate(self.ctx, out, &outl, data, inl):
raise Exception('EVP_EncryptUpdate failed')
return out[:inl]
finally:
Expand Down