static void block_init(block_state* self, unsigned char* key, int keylen) { int nr = 0; switch (keylen) { case 16: nr = 10; break; case 24: nr = 12; break; case 32: nr = 14; break; default: PyErr_SetString(PyExc_ValueError, "AES key must be either 16, 24, or 32 bytes long"); return; } /* ensure that self->ek and self->dk are aligned to 16 byte boundaries */ void* tek = aligned_malloc_wrapper(16, (nr + 1) * sizeof(__m128i)); void* tdk = aligned_malloc_wrapper(16, (nr + 1) * sizeof(__m128i)); if (!tek || !tdk) { aligned_free_wrapper(tek); aligned_free_wrapper(tdk); PyErr_SetString(PyExc_MemoryError, "failed to allocate memory for keys"); return; } self->ek = tek; self->dk = tdk; self->rounds = nr; aes_key_setup_enc(self->ek, key, keylen); aes_key_setup_dec(self->dk, self->ek, nr); }
static void block_init(block_state* self, unsigned char* key, int keylen) { int nr = 0; switch (keylen) { case 16: nr = 10; break; case 24: nr = 12; break; case 32: nr = 14; break; default: PyErr_SetString(PyExc_ValueError, "AES key must be either 16, 24, or 32 bytes long"); return; } self->rounds = nr; aes_key_setup_enc(self->ek, key, keylen); aes_key_setup_dec(self->dk, self->ek, nr); }
static int block_init(block_state* self, unsigned char* key, int keylen) { int nr = 0; int offset; switch (keylen) { case 16: nr = 10; break; case 24: nr = 12; break; case 32: nr = 14; break; default: return ERR_NR_ROUNDS; } /* ensure that self->ek and self->dk are aligned to 16 byte boundaries */ offset = ALIGNMENT - ((uintptr_t)self->buffer & (ALIGNMENT-1)); self->ek = (__m128i*)((uint8_t*)self->buffer + offset); self->dk = (__m128i*)((uint8_t*)self->ek + (MAXNR+1)*sizeof(__m128i)); self->rounds = nr; aes_key_setup_enc(self->ek, key, keylen); aes_key_setup_dec(self->dk, self->ek, nr); return 0; }