/** * Convert a hashcode into a key. * * @param hc hash code that serves to generate the key * @param skey set to a valid session key * @param iv set to a valid initialization vector */ void GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc, struct GNUNET_CRYPTO_AesSessionKey *skey, struct GNUNET_CRYPTO_AesInitializationVector *iv) { GNUNET_assert (sizeof (struct GNUNET_HashCode) >= GNUNET_CRYPTO_AES_KEY_LENGTH + sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); skey->crc32 = htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); }
int main (int argc, char *argv[]) { char buf[1024]; int i; GNUNET_log_setup ("test-crypto-crc", "WARNING", NULL); for (i = 0; i < 1024; i++) buf[i] = (char) i; for (i = 0; i < 1024; i++) if (expected[i] != GNUNET_CRYPTO_crc32_n (&buf[i], 1024 - i)) return 1; return 0; }