Skip to content

Commit

Permalink
Go down to C89
Browse files Browse the repository at this point in the history
  • Loading branch information
delivrance committed Mar 21, 2018
1 parent bf7dc4b commit 8471a40
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tgcrypto/ctr256.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ uint8_t *ctr256(const uint8_t in[], uint32_t length, const uint8_t key[32], cons
uint8_t *out = (uint8_t *) malloc(length * sizeof(uint8_t));
uint8_t iv_buf[AES_BLOCK_SIZE], out_buf[AES_BLOCK_SIZE];
uint32_t key_schedule[KEY_SCHEDULE_SIZE];
uint32_t i, j;

memcpy(out, in, length);
memcpy(iv_buf, iv, AES_BLOCK_SIZE);
aes256_key_expansion(key, key_schedule);

uint32_t i = 0, j;
if (length > AES_BLOCK_SIZE)
for (i = 0; i < length - AES_BLOCK_SIZE; i += AES_BLOCK_SIZE) {
aes256_encrypt(iv_buf, out_buf, key_schedule);
Expand Down
2 changes: 1 addition & 1 deletion tgcrypto/ige256.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ uint8_t *ige256(const uint8_t in[], uint32_t length, const uint8_t key[32], cons
uint8_t iv_1[AES_BLOCK_SIZE], iv_2[AES_BLOCK_SIZE];
uint8_t chunk[AES_BLOCK_SIZE], buffer[AES_BLOCK_SIZE];
uint32_t key_schedule[KEY_SCHEDULE_SIZE];
uint32_t i, j;

memcpy(encrypt ? iv_1 : iv_2, (uint8_t *) iv, AES_BLOCK_SIZE);
memcpy(encrypt ? iv_2 : iv_1, (uint8_t *) iv + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
aes256_key_expansion(key, key_schedule);

uint32_t i, j;
for (i = 0; i < length; i += AES_BLOCK_SIZE) {
memcpy(chunk, &in[i], AES_BLOCK_SIZE);

Expand Down
3 changes: 2 additions & 1 deletion tgcrypto/tgcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
static PyObject* tgcrypto(PyObject *args, uint8_t mode, uint8_t encrypt) {
Py_buffer data, key, iv;
uint8_t *(*fn)(), *buf;
PyObject* out;

PyArg_ParseTuple(args, "y*y*y*", &data, &key, &iv);
fn = encrypt? mode? ctr256_encrypt: ige256_encrypt: mode? ctr256_decrypt: ige256_decrypt;
Expand All @@ -33,7 +34,7 @@ static PyObject* tgcrypto(PyObject *args, uint8_t mode, uint8_t encrypt) {
PyBuffer_Release(&key);
PyBuffer_Release(&iv);

PyObject* out = Py_BuildValue("y#", buf, data.len);
out = Py_BuildValue("y#", buf, data.len);
free(buf);

return out;
Expand Down

0 comments on commit 8471a40

Please sign in to comment.