void cipher_set_key_string(CipherContext * context, int cipher, const char *passphrase, int for_encryption) { struct MD5Context md; unsigned char digest[16]; MD5Init(&md); MD5Update(&md, (const unsigned char *) passphrase, strlen(passphrase)); MD5Final(digest, &md); cipher_set_key(context, cipher, digest, 16, for_encryption); memset(digest, 0, sizeof(digest)); memset(&md, 0, sizeof(md)); }
void cipher_set_key_string(CipherContext *context, int cipher, const char *passphrase) { MD5_CTX md; unsigned char digest[16]; MD5_Init(&md); MD5_Update(&md, (const unsigned char *) passphrase, strlen(passphrase)); MD5_Final(digest, &md); cipher_set_key(context, cipher, digest, 16); memset(digest, 0, sizeof(digest)); memset(&md, 0, sizeof(md)); }
static void x917_generate(PRNG *ctx_, uint8_t *data, size_t len) { X917Context *ctx = (X917Context *)ctx_; BlockCipher *cipher = AES128_stackinit(); const size_t blen = cipher_block_len(cipher); uint8_t temp[blen]; ASSERT(len); ASSERT(sizeof(ctx->state) >= blen); ASSERT(sizeof(ctx->key) >= cipher_key_len(cipher)); cipher_set_key(cipher, ctx->key); while (len) { size_t L = MIN(blen, len); x917_next(ctx, cipher, temp); memcpy(data, temp, L); len -= L; data += L; } }