/* Return values: 0 = success, ERR_CIPHER_INIT_FAILURE (fatal), ERR_CIPHER_INIT_WEAK_KEY (non-fatal) */ int CipherInit (int cipher, unsigned char *key, unsigned __int8 *ks) { int retVal = ERR_SUCCESS; switch (cipher) { case GOST: gost_set_key(key, (gost_kds *)ks); break; default: // Unknown/wrong cipher ID return ERR_CIPHER_INIT_FAILURE; } return retVal; }
int main(int argc, char **argv) { uint8_t gamma[8]; uint8_t *in, *out; struct timeval t1, t2; gost_ctx ctx; gost_init(&ctx, &gost_sbox); gost_set_key(&ctx, &gost_key[0]); RAND_bytes(gamma, sizeof(gamma)); in = (uint8_t*) malloc(TEST_SIZE); assert(in != NULL); out = (uint8_t*) malloc(TEST_SIZE); assert(in != NULL); printf("TEST_SIZE: %d bytes\n", TEST_SIZE); gettimeofday(&t1, NULL); RAND_bytes(in, TEST_SIZE); gettimeofday(&t2, NULL); printf("RAND_bytes: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2)); gettimeofday(&t1, NULL); gost_ecb_encrypt(&ctx, &in[0], &out[0], TEST_SIZE/8); gettimeofday(&t2, NULL); printf("ECB mode: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2)); gettimeofday(&t1, NULL); gost_cfb_encrypt(&ctx, &gamma[0], &in[0], &out[0], TEST_SIZE/8); gettimeofday(&t2, NULL); printf("CFB mode: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2)); gettimeofday(&t1, NULL); gost_mac(&ctx, &in[0], TEST_SIZE, &out[0], 20); gettimeofday(&t2, NULL); printf("MAC mode: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2)); return 0; }
void CipherGost89StaticSBOX::SetCipherKey (const byte *key) { gost_set_key (key, (gost_kds *) ScheduledKey.Ptr(), 0); }
void CipherGost89::SetCipherKey (const byte *key) { gost_set_key (key, (gost_kds *) ScheduledKey.Ptr(), 1); }