Esempio n. 1
0
static int __init init_rc6(void)
{
	if (register_cipher(&rc6_ecb))
		printk(KERN_WARNING "Couldn't register rc6-ecb encryption\n");
	if (register_cipher(&rc6_cbc))
		printk(KERN_WARNING "Couldn't register rc6-cbc encryption\n");

	return 0;
}
Esempio n. 2
0
static int sqlcipher_ltc_activate(void *ctx) {
  ltc_ctx *ltc = (ltc_ctx*)ctx;
  int random_buffer_sz = 32;
  unsigned char random_buffer[random_buffer_sz];
  
  if(ltc_init == 0) {
    if(register_prng(&fortuna_desc) != CRYPT_OK) return SQLITE_ERROR;
    if(register_cipher(&rijndael_desc) != CRYPT_OK) return SQLITE_ERROR;
    if(register_hash(&sha1_desc) != CRYPT_OK) return SQLITE_ERROR;
    ltc_init = 1;
  }
  if(fortuna_start(&(ltc->prng)) != CRYPT_OK) {
    return SQLITE_ERROR;
  }
  sqlite3_randomness(random_buffer_sz, &random_buffer);
  if(sqlcipher_ltc_add_random(ctx, random_buffer, random_buffer_sz) != SQLITE_OK) {
    return SQLITE_ERROR;
  }
  if(sqlcipher_ltc_add_random(ctx, &ltc, sizeof(ltc_ctx*)) != SQLITE_OK) {
    return SQLITE_ERROR;
  }
  if(fortuna_ready(&(ltc->prng)) != CRYPT_OK) {
    return SQLITE_ERROR;
  }
  return SQLITE_OK;
}
Esempio n. 3
0
static int sqlcipher_ltc_activate(void *ctx) {
  unsigned char random_buffer[FORTUNA_MAX_SZ];
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  if(ltc_rand_mutex == NULL){
    ltc_rand_mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  }
  sqlite3_mutex_enter(ltc_rand_mutex);
#endif
  sqlcipher_memset(random_buffer, 0, FORTUNA_MAX_SZ);
  if(ltc_init == 0) {
    if(register_prng(&fortuna_desc) < 0) return SQLITE_ERROR;
    if(register_cipher(&rijndael_desc) < 0) return SQLITE_ERROR;
    if(register_hash(&sha512_desc) < 0) return SQLITE_ERROR;
    if(register_hash(&sha256_desc) < 0) return SQLITE_ERROR;
    if(register_hash(&sha1_desc) < 0) return SQLITE_ERROR;
    if(fortuna_start(&prng) != CRYPT_OK) {
      return SQLITE_ERROR;
    }
    ltc_init = 1;
  }
  ltc_ref_count++;
#ifndef SQLCIPHER_TEST
  sqlite3_randomness(FORTUNA_MAX_SZ, random_buffer);
#endif
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  sqlite3_mutex_leave(ltc_rand_mutex);
#endif
  if(sqlcipher_ltc_add_random(ctx, random_buffer, FORTUNA_MAX_SZ) != SQLITE_OK) {
    return SQLITE_ERROR;
  }
  sqlcipher_memset(random_buffer, 0, FORTUNA_MAX_SZ);
  return SQLITE_OK;
}
Esempio n. 4
0
/* format is ltc_mp, cipher_desc, [cipher_desc], NULL, hash_desc, [hash_desc], NULL, prng_desc, [prng_desc], NULL */
int crypt_fsa(void *mp, ...)
{
   int      err;
   va_list  args;
   void     *p;

   va_start(args, mp);
   if (mp != NULL) {
      XMEMCPY(&ltc_mp, mp, sizeof(ltc_mp));
   }
   
   while ((p = va_arg(args, void*)) != NULL) {
      if ((err = register_cipher(p)) != CRYPT_OK) {
         va_end(args);
         return err;
      }
   }

   while ((p = va_arg(args, void*)) != NULL) {
      if ((err = register_hash(p)) != CRYPT_OK) {
         va_end(args);
         return err;
      }
   }

   while ((p = va_arg(args, void*)) != NULL) {
      if ((err = register_prng(p)) != CRYPT_OK) {
         va_end(args);
         return err;
      }
   }

   va_end(args);
   return CRYPT_OK;   
}
Esempio n. 5
0
int main(int argc, char *argv[]){
  /* Similar situation as before,
     only the test vector is more complex.*/
  unsigned char key[32];
  bzero(key, 32);
  unsigned char initcount[16];
  bzero(initcount,16);
  initcount[15]=1; //For test usage
  unsigned char input[32];
  bzero(input, 32);
  unsigned char output[32]; //counter mode: assume xor works
  bzero(output, 32);
  aes256ctr(output, input, 32, key, initcount);
  for(int i=0; i<32; i++) printf("%02x ", output[i]);
  printf("\n");
  symmetric_CTR ctr;
  bzero(output, 32);
  register_cipher(&aes_desc);
  ctr_start(find_cipher("aes"), initcount, key, 32, 0, CTR_COUNTER_BIG_ENDIAN,
            &ctr);
  ctr_encrypt(input, output, 32, &ctr);
  ctr_done(&ctr);
  for(int i=0; i<32; i++) printf("%02x ", output[i]);
  printf("\n");
  exit(0);
}
Esempio n. 6
0
void ltc_init(void) 
{
    int cipherID;
    unsigned char key[ENCRYPTION_KEY_LENGTH];

#if defined(ENCRYPTION_CTR) || defined(ENCRYPTION_CBC)
    unsigned char IV[ENCRYPTION_BLOCK_LENGTH];
#endif

    TRACE_DEBUG("LTC: Initializing ...\n\r");

    // Register cipher
    register_cipher(&CIPHER_DESC);
    cipherID = find_cipher(CIPHER_NAME);

    // Load key
    ASCII2Hex(ENCRYPTION_KEY, key, ENCRYPTION_KEY_LENGTH);

#if defined(ENCRYPTION_CTR) || defined(ENCRYPTION_CBC)
    // Load IV
    ASCII2Hex(ENCRYPTION_IV, IV, ENCRYPTION_BLOCK_LENGTH);
#endif

    // Start decryption mode
#if defined(ENCRYPTION_ECB)
    ecb_start(cipherID, key, ENCRYPTION_KEY_LENGTH, 0, &sECB);
#elif defined(ENCRYPTION_CBC)
    cbc_start(cipherID, IV, key, ENCRYPTION_KEY_LENGTH, 0, &sCBC);
#elif defined(ENCRYPTION_CTR)
    ctr_start(cipherID, IV, key, ENCRYPTION_KEY_LENGTH, 0, CTR_COUNTER_BIG_ENDIAN, &sCTR);
#endif

    TRACE_DEBUG("LTC: Initialization done.\n\r");
}
Esempio n. 7
0
/* format is ltc_mp, cipher_desc, [cipher_desc], NULL, hash_desc, [hash_desc], NULL, prng_desc, [prng_desc], NULL */
int crypt_fsa(void *mp, ...)
{
   va_list  args;
   void     *p;

   va_start(args, mp);
   if (mp != NULL) {
      XMEMCPY(&ltc_mp, mp, sizeof(ltc_mp));
   }
   
   while ((p = va_arg(args, void*)) != NULL) {
      if (register_cipher(p) == -1) {
         va_end(args);
         return CRYPT_INVALID_CIPHER;
      }
   }

   while ((p = va_arg(args, void*)) != NULL) {
      if (register_hash(p) == -1) {
         va_end(args);
         return CRYPT_INVALID_HASH;
      }
   }

   while ((p = va_arg(args, void*)) != NULL) {
      if (register_prng(p) == -1) {
         va_end(args);
         return CRYPT_INVALID_PRNG;
      }
   }

   va_end(args);
   return CRYPT_OK;   
}
// =========================================================================
// Initialize libtomcrypt cypher
NTSTATUS
InitLTCCypher(
    OUT  int *cipher
)
{
	  NTSTATUS status = STATUS_CRYPTO_SYSTEM_INVALID;

    DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("InitLTCCypher\n")));

    // Initialize cipher
    *cipher = register_cipher(&cast5_desc);
    if (*cipher == -1)
        {
	    DEBUGOUTCYPHERIMPL(DEBUGLEV_ERROR, (TEXT("Could not register cipher\n")));
        }
    else
        {    
        *cipher = find_cipher("cast5");
        if (*cipher == -1)
            {
      	    DEBUGOUTCYPHERIMPL(DEBUGLEV_ERROR, (TEXT("Could not find cipher\n")));
            }
		else
			{
			status = STATUS_SUCCESS;
			}
        }

    DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("InitLTCCypher\n")));

	return status;
}
Esempio n. 9
0
  		CTomcryptInternals(void)
  	  {
  	    int ErrorCode = register_cipher(&rijndael_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	throw ExInternalError(std::string("Cannot register AES cipher."));
  	    }

  	    ErrorCode = register_prng(&fortuna_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	throw ExInternalError(std::string("Cannot register fortuna pseudo random generator."));
  	    }

  	    int const GeneratorID = find_prng("fortuna");
  	    ErrorCode = rng_make_prng(128, GeneratorID, &mRandomGenerator, NULL);
  	    if (ErrorCode != CRYPT_OK)
  	    {
  	    	throw ExInternalError(std::string("Error while starting random generator: ")+std::string(error_to_string(ErrorCode)));
  	    }

  	    ErrorCode = register_hash(&sha256_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	throw ExInternalError(std::string("Cannot register SHA2 hash."));
  	    }

  			return;
  	  }
Esempio n. 10
0
int main(void)
{
   register_cipher(&rijndael_enc_desc);
   register_prng(&yarrow_desc);
   register_hash(&sha256_desc);
   return 0;
}
Esempio n. 11
0
File: ezpup.c Progetto: aircross/ray
void register_algs(void)
{
    int x;

    register_cipher (&rc6_desc);
    register_cipher (&des3_desc);

    if (register_hash(&sha256_desc) == -1) {
        fprintf(stderr, "Error registering SHA256\n");
        exit(-1);
    } 

    if (register_prng(&yarrow_desc) == -1) {
        fprintf(stderr, "Error registering yarrow PRNG\n");
        exit(-1);
    }

    if (register_prng(&sprng_desc) == -1) {
        fprintf(stderr, "Error registering sprng PRNG\n");
        exit(-1);
    }
}
Esempio n. 12
0
File: c4.c Progetto: rhardman/C4
C4Err C4_Init()
{
    C4Err err = kC4Err_NoErr;
    
    ltc_mp = ltm_desc;

    register_prng (&sprng_desc);
    register_hash (&md5_desc);
    register_hash (&sha1_desc);
    register_hash (&sha256_desc);
    register_hash (&sha384_desc);
    register_hash (&sha512_desc);
    register_hash (&sha224_desc);
    register_hash (&skein256_desc);
    register_hash (&skein512_desc);
    register_hash (&skein1024_desc);
    register_hash (&sha512_256_desc);
    register_cipher (&aes_desc);
    register_cipher (&twofish_desc);
    
    return err;
}
Esempio n. 13
0
void register_algs(void)
{
  int err;

#ifdef TIGER
  register_hash (&tiger_desc);
#endif
#ifdef MD2
  register_hash (&md2_desc);
#endif
#ifdef MD4
  register_hash (&md4_desc);
#endif
#ifdef MD5
  register_hash (&md5_desc);
#endif
#ifdef SHA1
  register_hash (&sha1_desc);
#endif
#ifdef SHA224
  register_hash (&sha224_desc);
#endif
#ifdef SHA256
  register_hash (&sha256_desc);
#endif
#ifdef SHA384
  register_hash (&sha384_desc);
#endif
#ifdef SHA512
  register_hash (&sha512_desc);
#endif
#ifdef RIPEMD128
  register_hash (&rmd128_desc);
#endif
#ifdef RIPEMD160
  register_hash (&rmd160_desc);
#endif
#ifdef WHIRLPOOL
  register_hash (&whirlpool_desc);
#endif
#ifdef CHC_HASH
  register_hash(&chc_desc);
  if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) {
     printf("chc_register error: %s\n", error_to_string(err));
     exit(EXIT_FAILURE);
  }
#endif

}
Esempio n. 14
0
/* Register the compiled in ciphers.
 * This should be run before using any of the ciphers/hashes */
void crypto_init() {

	const struct ltc_cipher_descriptor *regciphers[] = {
#ifdef DROPBEAR_AES
		&aes_desc,
#endif
#ifdef DROPBEAR_BLOWFISH
		&blowfish_desc,
#endif
#ifdef DROPBEAR_TWOFISH
		&twofish_desc,
#endif
#ifdef DROPBEAR_3DES
		&des3_desc,
#endif
		NULL
	};

	const struct ltc_hash_descriptor *reghashes[] = {
		/* we need sha1 for hostkey stuff regardless */
		&sha1_desc,
#ifdef DROPBEAR_MD5_HMAC
		&md5_desc,
#endif
#ifdef DROPBEAR_SHA2_256_HMAC
		&sha256_desc,
#endif
#ifdef DROPBEAR_SHA2_512_HMAC
		&sha512_desc,
#endif
		NULL
	};	
	int i;
	
	for (i = 0; regciphers[i] != NULL; i++) {
		if (register_cipher(regciphers[i]) == -1) {
			dropbear_exit("Error registering crypto");
		}
	}

	for (i = 0; reghashes[i] != NULL; i++) {
		if (register_hash(reghashes[i]) == -1) {
			dropbear_exit("Error registering crypto");
		}
	}
}
Esempio n. 15
0
int my_aes_setup(int tmpKey){
	if (register_cipher(&aes_desc) == -1) {
		printf("Error registering aes\n");
		exit(EXIT_FAILURE);
	}
	
	unsigned char key[32];
	unsigned long keyLength = 32;
	hash_memory(hash_index,(unsigned char*)&tmpKey, sizeof(int), key, &keyLength);

	int err;
	if ((err = cipher_descriptor[find_cipher("aes")].setup(key, keyLength, 0, &symKey)) != CRYPT_OK) {
		printf("Error setting up AES ,%i, %s\n",err, error_to_string(err));
		exit(EXIT_FAILURE);
	}
	return 0;
}
Esempio n. 16
0
int symmetricEncrypt(unsigned char *key, unsigned long keylen, unsigned char *in, unsigned long len, unsigned char *IV, unsigned long ivlen)
{
    symmetric_CTR ctr;
    int err;

    /* register aes first */
    
    if ((err = register_cipher(&rijndael_desc)) == -1) {
        return ERROR_REG_AES;
    }
    
    /* start up CTR mode */
    if ((err = ctr_start(
        find_cipher("rijndael"),    /* index of desired cipher */
                             IV,    /* the initial vecoter */ 
                            key,    /* the secret key */
                         keylen,    /* length of secret key */
                              0,
      CTR_COUNTER_LITTLE_ENDIAN,
                           &ctr)
        ) != CRYPT_OK) {
        //printf("%s\n", error_to_string(err));
        return err;
    }
    /*
    printf("from libcrypt: \n");
    for(i = 0; i < 30; i++)
        printf("%02x ", in[i]);
    printf("\n");
    fflush(stdout);
    */
    if ((err = ctr_encrypt(     in, /* plaintext */
                                in, /* ciphertext */
                                   len, /* length of plaintext */
                                  &ctr) /* CTR state */
        ) != CRYPT_OK) {
        return err;
    }

    if ((err = ctr_done(&ctr)) != CRYPT_OK) {
        return err;
    }

    return CRYPT_OK;
}
Esempio n. 17
0
void aes256gcmtomcrypt(unsigned char *c, unsigned char *m,
                    unsigned long long mlen, unsigned char *nonce,
                    unsigned char *key){
  /*Using libtomcrypt as alternative gives us way to check implementation*/
  register_cipher(&aes_desc);
  unsigned char tag[16];
  unsigned long taglen=16;
  unsigned char decryptag[16];
  unsigned char j0[16];
  memcpy(j0, nonce, 12);
  j0[12]=0;
  j0[13]=0;
  j0[14]=0;
  j0[15]=1;
  gcm_memory(find_cipher("aes"), key, 32, nonce, 12, 0, 0, m+16, mlen-16,
             c+16, tag, &taglen ,GCM_ENCRYPT);
  memcpy(c, tag, 16);
}
Esempio n. 18
0
int symmetricDecrypt(unsigned char *key, unsigned long keylen, unsigned char *in, unsigned long len, unsigned char *IV, unsigned long ivlen)
{
    symmetric_CTR ctr;
    int err;

    /* register aes first */
    if (register_cipher(&rijndael_desc) == -1) {
        return ERROR_REG_AES;
    }
    
    /* start up CTR mode */
    if ((err = ctr_start(
        find_cipher("rijndael"),    /* index of desired cipher */
                             IV,    /* the initial vecoter */ 
                            key,    /* the secret key */
                         keylen,    /* length of secret key */
                              0,
      CTR_COUNTER_LITTLE_ENDIAN,
                           &ctr)
        ) != CRYPT_OK) {
        return err;
    }

//    if ((err = ctr_setiv( IV, /* the initial IV we gave to ctr_start */
//                    16, /* the IV is 16 bytes long */
//                    &ctr) /* the ctr state we wish to modify */
//        ) != CRYPT_OK) {
//        printf("ctr_setiv error: %s\n", error_to_string(err));
//        return -1;
//    }

    if ((err = ctr_decrypt(     in, /* plaintext */
                                in, /* ciphertext */
                               len, /* length of plaintext */
                              &ctr) /* CTR state */
        ) != CRYPT_OK) {
        return err;
    }
    if ((err = ctr_done(&ctr)) != CRYPT_OK) {
        return err;
    }

    return CRYPT_OK;
}
Esempio n. 19
0
void ltc_init_3DES_ECB(void) 
{
    int cipherID;
    unsigned char key[ENCRYPTION_KEY_LENGTH];

    TRACE_DEBUG("LTC: Initializing ECB...\n\r");

    // Register cipher
    register_cipher(&des3_desc);
    cipherID = find_cipher("3des");

    // Load key
    ASCII2Hex(ENCRYPTION_KEY, key, ENCRYPTION_KEY_LENGTH);

    // Start decryption mode
    ecb_start(cipherID, key, ENCRYPTION_KEY_LENGTH, 0, &sECB);

    TRACE_DEBUG("LTC: Initialization done.\n\r");
}
Esempio n. 20
0
void DB_AuthLoad_InitCrypto()
{
    if (ffVersion < 319)
    {
        return;
    }

    register_hash(&sha256_desc);
    register_cipher(&aes_desc);

    unsigned char encKey[256];
    DB_ReadXFileRawData(encKey, 256);

    ZoneKey key;
    DB_AuthLoad_DecryptKey(encKey, &key);

    int aes = find_cipher("aes");
    ctr_start(aes, key.iv, key.key, sizeof(key.key), 0, 0, &ffCTR);

    memcpy(ffIV, key.iv, sizeof(ffIV));
}
Esempio n. 21
0
/* Register the compiled in ciphers.
 * This should be run before using any of the ciphers/hashes */
void crypto_init() {

	const struct _cipher_descriptor *regciphers[] = {
#ifdef DROPBEAR_AES128_CBC
		&rijndael_desc,
#endif
#ifdef DROPBEAR_BLOWFISH_CBC
		&blowfish_desc,
#endif
#ifdef DROPBEAR_TWOFISH128_CBC
		&twofish_desc,
#endif
#ifdef DROPBEAR_3DES_CBC
		&des3_desc,
#endif
		NULL
	};

	const struct _hash_descriptor *reghashes[] = {
		/* we need sha1 for hostkey stuff regardless */
		&sha1_desc,
#ifdef DROPBEAR_MD5_HMAC
		&md5_desc,
#endif
		NULL
	};	
	int i;
	
	for (i = 0; regciphers[i] != NULL; i++) {
		if (register_cipher(regciphers[i]) == -1) {
			dropbear_exit("error registering crypto");
		}
	}

	for (i = 0; reghashes[i] != NULL; i++) {
		if (register_hash(reghashes[i]) == -1) {
			dropbear_exit("error registering crypto");
		}
	}
}
Esempio n. 22
0
void ltc_init_AES_CBC(void) 
{
    int cipherID;
    unsigned char key[ENCRYPTION_KEY_LENGTH];
    unsigned char IV[ENCRYPTION_BLOCK_LENGTH];

    TRACE_DEBUG("LTC: Initializing CBC...\n\r");

    // Register cipher
    register_cipher(&rijndael_desc);
    cipherID = find_cipher("rijndael");

    // Load key
    ASCII2Hex(ENCRYPTION_KEY, key, ENCRYPTION_KEY_LENGTH);

    // Load IV
    ASCII2Hex(ENCRYPTION_IV, IV, ENCRYPTION_BLOCK_LENGTH);

    // Start decryption mode
    cbc_start(cipherID, IV, key, ENCRYPTION_KEY_LENGTH, 0, &sCBC);

    TRACE_DEBUG("LTC: Initialization done.\n\r");
}
Esempio n. 23
0
void ltc_init_3DES_CTR(void) 
{
    int cipherID;
    unsigned char key[ENCRYPTION_KEY_LENGTH];
    unsigned char IV[ENCRYPTION_BLOCK_LENGTH];

    TRACE_DEBUG("LTC: Initializing CTR...\n\r");

    // Register cipher
    register_cipher(&des3_desc);
    cipherID = find_cipher("3des");

    // Load key
    ASCII2Hex(ENCRYPTION_KEY, key, ENCRYPTION_KEY_LENGTH);

    // Load IV
    ASCII2Hex(ENCRYPTION_IV, IV, ENCRYPTION_BLOCK_LENGTH);

    // Start decryption mode
    ctr_start(cipherID, IV, key, ENCRYPTION_KEY_LENGTH, 0, CTR_COUNTER_BIG_ENDIAN, &sCTR);

    TRACE_DEBUG("LTC: Initialization done.\n\r");
}
/**
  Start the PRNG
  @param prng     [out] The PRNG state to initialize
  @return CRYPT_OK if successful
*/  
int yarrow_start(prng_state *prng)
{
   int err;
   
   LTC_ARGCHK(prng != NULL);

   /* these are the default hash/cipher combo used */
#ifdef RIJNDAEL
#if    YARROW_AES==0
   prng->yarrow.cipher = register_cipher(&rijndael_enc_desc);
#elif  YARROW_AES==1
   prng->yarrow.cipher = register_cipher(&aes_enc_desc);
#elif  YARROW_AES==2
   prng->yarrow.cipher = register_cipher(&rijndael_desc);
#elif  YARROW_AES==3
   prng->yarrow.cipher = register_cipher(&aes_desc);
#endif
#elif defined(BLOWFISH)
   prng->yarrow.cipher = register_cipher(&blowfish_desc);
#elif defined(TWOFISH)
   prng->yarrow.cipher = register_cipher(&twofish_desc);
#elif defined(RC6)
   prng->yarrow.cipher = register_cipher(&rc6_desc);
#elif defined(RC5)
   prng->yarrow.cipher = register_cipher(&rc5_desc);
#elif defined(SAFERP)
   prng->yarrow.cipher = register_cipher(&saferp_desc);
#elif defined(RC2)
   prng->yarrow.cipher = register_cipher(&rc2_desc);
#elif defined(NOEKEON)   
   prng->yarrow.cipher = register_cipher(&noekeon_desc);
#elif defined(CAST5)
   prng->yarrow.cipher = register_cipher(&cast5_desc);
#elif defined(XTEA)
   prng->yarrow.cipher = register_cipher(&xtea_desc);
#elif defined(SAFER)
   prng->yarrow.cipher = register_cipher(&safer_sk128_desc);
#elif defined(DES)
   prng->yarrow.cipher = register_cipher(&des3_desc);
#else
   #error YARROW needs at least one CIPHER
#endif
   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
      return err;
   }

#ifdef SHA256
   prng->yarrow.hash   = register_hash(&sha256_desc);
#elif defined(SHA512)
   prng->yarrow.hash   = register_hash(&sha512_desc);
#elif defined(TIGER)
   prng->yarrow.hash   = register_hash(&tiger_desc);
#elif defined(SHA1)
   prng->yarrow.hash   = register_hash(&sha1_desc);
#elif defined(RIPEMD160)
   prng->yarrow.hash   = register_hash(&rmd160_desc);
#elif defined(RIPEMD128)
   prng->yarrow.hash   = register_hash(&rmd128_desc);
#elif defined(MD5)
   prng->yarrow.hash   = register_hash(&md5_desc);
#elif defined(MD4)
   prng->yarrow.hash   = register_hash(&md4_desc);
#elif defined(MD2)
   prng->yarrow.hash   = register_hash(&md2_desc);
#elif defined(WHIRLPOOL)
   prng->yarrow.hash   = register_hash(&whirlpool_desc);
#else
   #error YARROW needs at least one HASH
#endif
   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
      return err;
   }

   /* zero the memory used */
   zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool));

   return CRYPT_OK;
}
Esempio n. 25
0
int TestStorageCiphers()
{
    int err = CRYPT_OK;
    int idx;
    unsigned int		i;

     

    static uint64_t K1[] = { 0L, 0L, 0L, 0L };
    static uint64_t P1[] = { 0L, 0L, 0L, 0L };
    static uint64_t C1[] = { 0x94EEEA8B1F2ADA84L, 0xADF103313EAE6670L, 0x952419A1F4B16D53L, 0xD83F13E63C9F6B11L };
    static uint64_t T1[] = { 0L, 0L };
 
    static uint64_t K2[] = { 0x1716151413121110L, 0x1F1E1D1C1B1A1918L,  0x2726252423222120L, 0x2F2E2D2C2B2A2928L };
    static uint64_t P2[] = { 0xF8F9FAFBFCFDFEFFL, 0xF0F1F2F3F4F5F6F7L,  0xE8E9EAEBECEDEEEFL, 0xE0E1E2E3E4E5E6E7L };
    static uint64_t C2[] = { 0XDF8FEA0EFF91D0E0L, 0XD50AD82EE69281C9L, 0X76F48D58085D869DL, 0XDF975E95B5567065L };
    static uint64_t T2[] = { 0x0706050403020100L, 0x0F0E0D0C0B0A0908L };
 
    static uint64_t K3[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    static uint64_t P3[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    static uint64_t T3[] = { 0L, 0L };
    static uint64_t C3[] = { 0xBC2560EFC6BBA2B1L, 0xE3361F162238EB40L, 0xFB8631EE0ABBD175L, 0x7B9479D4C5479ED1L, 
                             0xCFF0356E58F8C27BL, 0xB1B7B08430F0E7F7L, 0xE9A380A56139ABF1L, 0xBE7B6D4AA11EB47EL };
    
    static uint64_t K4[] = { 0x1716151413121110L, 0x1F1E1D1C1B1A1918L, 0x2726252423222120L, 0x2F2E2D2C2B2A2928L, 
                             0x3736353433323130L, 0x3F3E3D3C3B3A3938L, 0x4746454443424140L, 0x4F4E4D4C4B4A4948L };
    static uint64_t P4[] = { 0xF8F9FAFBFCFDFEFFL, 0xF0F1F2F3F4F5F6F7L, 0xE8E9EAEBECEDEEEFL, 0xE0E1E2E3E4E5E6E7L, 
                             0xD8D9DADBDCDDDEDFL, 0xD0D1D2D3D4D5D6D7L, 0xC8C9CACBCCCDCECFL, 0xC0C1C2C3C4C5C6C7L };
    static uint64_t T4[] = { 0x0706050403020100L, 0x0F0E0D0C0B0A0908L };
    static uint64_t C4[] = { 0x2C5AD426964304E3L, 0x9A2436D6D8CA01B4L, 0xDD456DB00E333863L, 0x794725970EB9368BL, 
                             0x043546998D0A2A27L, 0x25A7C918EA204478L, 0x346201A1FEDF11AFL, 0x3DAF1C5C3D672789L };
    
    static uint64_t K5[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    static uint64_t P5[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
    static uint64_t T5[] = { 0L, 0L };
    static uint64_t C5[] = { 0x04B3053D0A3D5CF0L, 0x0136E0D1C7DD85F7L, 0x067B212F6EA78A5CL, 0x0DA9C10B4C54E1C6L,
                            0x0F4EC27394CBACF0L, 0x32437F0568EA4FD5L, 0xCFF56D1D7654B49CL, 0xA2D5FB14369B2E7BL, 
                            0x540306B460472E0BL, 0x71C18254BCEA820DL, 0xC36B4068BEAF32C8L, 0xFA4329597A360095L, 
                            0xC4A36C28434A5B9AL, 0xD54331444B1046CFL, 0xDF11834830B2A460L, 0x1E39E8DFE1F7EE4FL  }; 
                        
    static uint64_t K6[] = { 0x1716151413121110L, 0x1F1E1D1C1B1A1918L, 0x2726252423222120L, 0x2F2E2D2C2B2A2928L, 
                            0x3736353433323130L, 0x3F3E3D3C3B3A3938L, 0x4746454443424140L, 0x4F4E4D4C4B4A4948L, 
                            0x5756555453525150L, 0x5F5E5D5C5B5A5958L, 0x6766656463626160L, 0x6F6E6D6C6B6A6968L, 
                            0x7776757473727170L, 0x7F7E7D7C7B7A7978L, 0x8786858483828180L, 0x8F8E8D8C8B8A8988L };
    static uint64_t P6[] = { 0xF8F9FAFBFCFDFEFFL, 0xF0F1F2F3F4F5F6F7L, 0xE8E9EAEBECEDEEEFL, 0xE0E1E2E3E4E5E6E7L, 
                            0xD8D9DADBDCDDDEDFL, 0xD0D1D2D3D4D5D6D7L, 0xC8C9CACBCCCDCECFL, 0xC0C1C2C3C4C5C6C7L, 
                            0xB8B9BABBBCBDBEBFL, 0xB0B1B2B3B4B5B6B7L, 0xA8A9AAABACADAEAFL, 0xA0A1A2A3A4A5A6A7L, 
                            0x98999A9B9C9D9E9FL, 0x9091929394959697L, 0x88898A8B8C8D8E8FL, 0x8081828384858687L };
    static uint64_t T6[] = { 0x0706050403020100L, 0x0F0E0D0C0B0A0908L };
    static uint64_t C6[] = { 0xB0C33CD7DB4D65A6L, 0xBC49A85A1077D75DL, 0x6855FCAFEA7293E4L, 0x1C5385AB1B7754D2L, 
                            0x30E4AAFFE780F794L, 0xE1BBEE708CAFD8D5L, 0x9CA837B7423B0F76L, 0xBD1403670D4963B3L, 
                            0x451F2E3CE61EA48AL, 0xB360832F9277D4FBL, 0x0AAFC7A65E12D688L, 0xC8906E79016D05D7L, 
                            0xB316570A15F41333L, 0x74E98A2869F5D50EL, 0x57CE6F9247432BCEL, 0xDE7CDD77215144DEL  };


	     
    printf("\nTesting Storage Ciphers\n");
    
    register_cipher (&threefish_desc);
    
    if ((idx = find_cipher("threefish")) == -1) {
             return CRYPT_NOP;
        }
    
    storage_katvector storage_kat_vector_array[] = 
	{
        { idx, 256,	K1, T1,	P1, sizeof(P1), C1, sizeof(C1) },
        { idx, 256,	K2, T2,	P2, sizeof(P2), C2, sizeof(C2) },
        
        { idx, 512,	K3, T3,	P3, sizeof(P3), C3, sizeof(C3) },
        { idx, 512,	K4, T4,	P4, sizeof(P4), C4, sizeof(C4) },
        
        { idx, 1024,K5, T5,	P5, sizeof(P5), C5, sizeof(C5) },
        { idx, 1024,K6, T6,	P6, sizeof(P6), C6, sizeof(C6) } 
    };
     
    /* run  known answer tests (KAT) */
  	for (i = 0; i < sizeof(storage_kat_vector_array)/ sizeof(storage_katvector) ; i++)
	{
        DO( RunStorageCipherKAT( &storage_kat_vector_array[i] ));
        
	}

 
    return err;
    
}
Esempio n. 26
0
int TestCiphers()
{
    int err = CRYPT_OK;
    int idx;
    
    unsigned int		i;
    
    uint8_t P1[512];
    
    /* Test vectors for ECB known answer test */
    /* AES 128 bit key */
    uint8_t K1[] = {
		0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08,
		0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12
	};
    
    uint8_t IV1[] = {
 		0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12, 0x14, 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C
	};
    
    uint8_t Cebc1[] = {
		0xc7, 0xb1, 0x3e, 0x86, 0xa2, 0x16, 0xe2, 0x9c, 0x52, 0x2a, 0x5d, 0x12, 0x97, 0xe5, 0x6c, 0x49, 
		0x1d, 0xf9, 0x0c, 0xd4, 0x73, 0x3a, 0xbc, 0x69, 0x86, 0x66, 0x4e, 0x11, 0xf3, 0x1a, 0x54, 0xd2, 
		0x47, 0xc2, 0xe0, 0x0e, 0xdb, 0x0a, 0x54, 0x3b, 0x01, 0x0e, 0x45, 0x97, 0x4d, 0x9e, 0x31, 0x08, 
		0x35, 0x18, 0x5c, 0xf3, 0x07, 0x86, 0xac, 0xa4, 0x7e, 0x3b, 0x60, 0x30, 0x53, 0xd0, 0x3f, 0x1c, 
	};
    
    uint8_t Ccbc1[] = {
        0x7e, 0x0c, 0xd0, 0x7e, 0x6d, 0xd9, 0xb8, 0x5a, 0xba, 0xf7, 0x66, 0x3c, 0xa6, 0xb2, 0xe4, 0x36, 
        0x6e, 0x8c, 0x2f, 0xcf, 0x57, 0xd5, 0x77, 0xba, 0x75, 0xa8, 0xb4, 0x4d, 0x23, 0x40, 0xa7, 0x88, 
        0x16, 0x30, 0x22, 0x48, 0x7d, 0x70, 0xd2, 0x9f, 0x21, 0xac, 0x79, 0x7f, 0x83, 0x50, 0x36, 0x25, 
        0xa7, 0xd9, 0xf9, 0xdd, 0x74, 0xe5, 0xc0, 0x6c, 0xc6, 0x25, 0x0d, 0x8f, 0x5d, 0xd0, 0xde, 0xc6, 
	};
 	
   	
    /* AES 192 bit key */
    uint8_t K2[] = {
		0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08,
		0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12,
		0x14, 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C
	};
    uint8_t Cebc2[] = {
		0x11, 0x40, 0x98, 0x78, 0x0a, 0x5c, 0xda, 0xb5, 0xec, 0xe2, 0x24, 0x04, 0x73, 0x29, 0x3c, 0xfa, 
		0x9e, 0xfa, 0x77, 0xa0, 0x36, 0x44, 0xde, 0x99, 0xe5, 0x71, 0xa5, 0xb5, 0x80, 0x6e, 0xc0, 0x91, 
		0x0f, 0xd9, 0x51, 0x4d, 0x6e, 0x43, 0x23, 0x82, 0x7a, 0x51, 0xd8, 0xd9, 0xf7, 0x3d, 0xb7, 0xa5, 
		0x54, 0x35, 0x2e, 0x6d, 0x4f, 0x89, 0xfe, 0xe5, 0x9b, 0x9d, 0x33, 0xff, 0xde, 0x68, 0xe6, 0x7f 
	};
    
    uint8_t Ccbc2[] = {
        0xb8, 0x66, 0xd6, 0xca, 0x74, 0xfe, 0xb4, 0x4e, 0x2a, 0x51, 0xfa, 0xf3, 0x83, 0xfe, 0x09, 0xb9, 
        0xc5, 0x63, 0x8b, 0xec, 0x5d, 0x5c, 0xc1, 0x5e, 0x65, 0x89, 0x9e, 0x9f, 0x1f, 0x94, 0x85, 0xb1, 
        0x6a, 0xd7, 0x51, 0x1b, 0x35, 0x69, 0xfe, 0x09, 0x73, 0x24, 0xd4, 0xa4, 0x9d, 0x5f, 0xf5, 0x84, 
        0x7e, 0x2a, 0x47, 0x4e, 0x39, 0x7a, 0x35, 0xa8, 0x95, 0xb3, 0x31, 0x1b, 0x81, 0xca, 0xb1, 0x5c, 
	};
    
	
    /* AES 256 bit key */
    uint8_t K3[] = {
		0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08,
		0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12,
		0x14, 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C,
		0x1E, 0x1F, 0x20, 0x21, 0x23, 0x24, 0x25, 0x26
	};
    uint8_t Cebc3[] = {
		0xda, 0xd2, 0xa9, 0x13, 0x2f, 0x24, 0xf9, 0x97, 0x93, 0xfe, 0x81, 0x10, 0x4a, 0xd5, 0x8a, 0x63, 
		0xa9, 0x1a, 0x1f, 0x49, 0xb9, 0x9c, 0xd8, 0x37, 0x0a, 0x5c, 0xa9, 0xae, 0x55, 0xcb, 0x17, 0xee, 
		0x01, 0xa8, 0xda, 0x61, 0x41, 0x0b, 0xca, 0xaa, 0xda, 0x5d, 0xdf, 0xfd, 0x8b, 0xea, 0xc7, 0x09, 
		0x0d, 0x22, 0x1f, 0xef, 0x3f, 0x03, 0x16, 0x02, 0xfa, 0x87, 0xf0, 0x47, 0x73, 0xde, 0x77, 0xd4, 
	};
    
    uint8_t Ccbc3[] = {
        0x2c, 0x93, 0x91, 0xa6, 0xc1, 0x22, 0x1b, 0xe6, 0x6f, 0x49, 0x4b, 0x07, 0x18, 0x17, 0x97, 0xd9, 
        0x9f, 0x52, 0xac, 0xa2, 0x99, 0x4c, 0x25, 0x9e, 0x3e, 0x3e, 0xa5, 0xa1, 0x11, 0xa4, 0xe7, 0x84, 
        0x89, 0xa0, 0x1a, 0x5c, 0xff, 0x12, 0xf5, 0x39, 0xc0, 0xa6, 0x8d, 0x4f, 0x30, 0x6a, 0x2f, 0x1e, 
        0x87, 0xec, 0x63, 0x52, 0x7d, 0xf7, 0x86, 0x40, 0x28, 0xa1, 0x89, 0xbd, 0x1d, 0xb5, 0xc3, 0x00, 
	};
 	
    printf("\nTesting Ciphers\n");
 
    register_cipher (&aes_desc);
  
    if ((idx = find_cipher("aes")) == -1) {
        if ((idx = find_cipher("rijndael")) == -1) {
            return CRYPT_NOP;
        }
    }
      
    katvector kat_vector_array[] = 
	{
        {	idx, 128,	K1, P1, 64,	 IV1, Cebc1, sizeof(Cebc1),  Ccbc1, sizeof(Ccbc1) },
        {	idx, 192,	K2, P1, 64,  IV1, Cebc2, sizeof(Cebc2),  Ccbc2, sizeof(Ccbc2)},
        {	idx, 256,   K3, P1, 64,  IV1, Cebc3, sizeof(Cebc3),  Ccbc3, sizeof(Ccbc3)},		
	};
 
    
    /* init the P1 */
	for (i = 0; i < sizeof(P1) ; i++) P1[i] = i;
    
    /* run  known answer tests (KAT) */
	for (i = 0; i < sizeof(kat_vector_array)/ sizeof(katvector) ; i++)
	{
        DO( RunCipherKAT( &kat_vector_array[i] ));
        
	}
    
    return err;
}
Esempio n. 27
0
/**
  Start the PRNG
  @param prng     [out] The PRNG state to initialize
  @return CRYPT_OK if successful
*/  
int yarrow_start(prng_state *prng)
{
   int err;
   
   LTC_ARGCHK(prng != NULL);

   /* these are the default hash/cipher combo used */
#ifdef LTC_RIJNDAEL
#if    LTC_YARROW_AES==0
   prng->yarrow.cipher = register_cipher(&rijndael_enc_desc);
#elif  LTC_YARROW_AES==1
   prng->yarrow.cipher = register_cipher(&aes_enc_desc);
#elif  LTC_YARROW_AES==2
   prng->yarrow.cipher = register_cipher(&rijndael_desc);
#elif  LTC_YARROW_AES==3
   prng->yarrow.cipher = register_cipher(&aes_desc);
#endif
#elif defined(LTC_BLOWFISH)
   prng->yarrow.cipher = register_cipher(&blowfish_desc);
#elif defined(LTC_TWOFISH)
   prng->yarrow.cipher = register_cipher(&twofish_desc);
#elif defined(LTC_RC6)
   prng->yarrow.cipher = register_cipher(&rc6_desc);
#elif defined(LTC_RC5)
   prng->yarrow.cipher = register_cipher(&rc5_desc);
#elif defined(LTC_SAFERP)
   prng->yarrow.cipher = register_cipher(&saferp_desc);
#elif defined(LTC_RC2)
   prng->yarrow.cipher = register_cipher(&rc2_desc);
#elif defined(LTC_NOEKEON)   
   prng->yarrow.cipher = register_cipher(&noekeon_desc);
#elif defined(LTC_ANUBIS)   
   prng->yarrow.cipher = register_cipher(&anubis_desc);
#elif defined(LTC_KSEED)   
   prng->yarrow.cipher = register_cipher(&kseed_desc);
#elif defined(LTC_KHAZAD)   
   prng->yarrow.cipher = register_cipher(&khazad_desc);
#elif defined(LTC_CAST5)
   prng->yarrow.cipher = register_cipher(&cast5_desc);
#elif defined(LTC_XTEA)
   prng->yarrow.cipher = register_cipher(&xtea_desc);
#elif defined(LTC_SAFER)
   prng->yarrow.cipher = register_cipher(&safer_sk128_desc);
#elif defined(LTC_DES)
   prng->yarrow.cipher = register_cipher(&des3_desc);
#else
   #error LTC_YARROW needs at least one CIPHER
#endif
   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
      return err;
   }

#ifdef LTC_SHA256
   prng->yarrow.hash   = register_hash(&sha256_desc);
#elif defined(LTC_SHA512)
   prng->yarrow.hash   = register_hash(&sha512_desc);
#elif defined(LTC_TIGER)
   prng->yarrow.hash   = register_hash(&tiger_desc);
#elif defined(LTC_SHA1)
   prng->yarrow.hash   = register_hash(&sha1_desc);
#elif defined(LTC_RIPEMD320)
   prng->yarrow.hash   = register_hash(&rmd320_desc);
#elif defined(LTC_RIPEMD256)
   prng->yarrow.hash   = register_hash(&rmd256_desc);
#elif defined(LTC_RIPEMD160)
   prng->yarrow.hash   = register_hash(&rmd160_desc);
#elif defined(LTC_RIPEMD128)
   prng->yarrow.hash   = register_hash(&rmd128_desc);
#elif defined(LTC_MD5)
   prng->yarrow.hash   = register_hash(&md5_desc);
#elif defined(LTC_MD4)
   prng->yarrow.hash   = register_hash(&md4_desc);
#elif defined(LTC_MD2)
   prng->yarrow.hash   = register_hash(&md2_desc);
#elif defined(LTC_WHIRLPOOL)
   prng->yarrow.hash   = register_hash(&whirlpool_desc);
#else
   #error LTC_YARROW needs at least one HASH
#endif
   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
      return err;
   }

   /* zero the memory used */
   zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool));
   LTC_MUTEX_INIT(&prng->yarrow.prng_lock)

   return CRYPT_OK;
}
Esempio n. 28
0
void register_algs(void)
{
   int x;
   
#ifdef LTC_RIJNDAEL
  register_cipher (&aes_desc);
#endif
#ifdef LTC_BLOWFISH
  register_cipher (&blowfish_desc);
#endif
#ifdef LTC_XTEA
  register_cipher (&xtea_desc);
#endif
#ifdef LTC_RC5
  register_cipher (&rc5_desc);
#endif
#ifdef LTC_RC6
  register_cipher (&rc6_desc);
#endif
#ifdef LTC_SAFERP
  register_cipher (&saferp_desc);
#endif
#ifdef LTC_TWOFISH
  register_cipher (&twofish_desc);
#endif
#ifdef LTC_SAFER
  register_cipher (&safer_k64_desc);
  register_cipher (&safer_sk64_desc);
  register_cipher (&safer_k128_desc);
  register_cipher (&safer_sk128_desc);
#endif
#ifdef LTC_RC2
  register_cipher (&rc2_desc);
#endif
#ifdef LTC_DES
  register_cipher (&des_desc);
  register_cipher (&des3_desc);
#endif
#ifdef LTC_CAST5
  register_cipher (&cast5_desc);
#endif
#ifdef LTC_NOEKEON
  register_cipher (&noekeon_desc);
#endif
#ifdef LTC_SKIPJACK
  register_cipher (&skipjack_desc);
#endif
#ifdef LTC_KHAZAD
  register_cipher (&khazad_desc);
#endif
#ifdef LTC_ANUBIS
  register_cipher (&anubis_desc);
#endif

   if (register_hash(&sha256_desc) == -1) {
      printf("Error registering LTC_SHA256\n");
      exit(-1);
   } 

   if (register_prng(&yarrow_desc) == -1) {
      printf("Error registering yarrow PRNG\n");
      exit(-1);
   }

   if (register_prng(&sprng_desc) == -1) {
      printf("Error registering sprng PRNG\n");
      exit(-1);
   }
}
Esempio n. 29
0
int main(){
	char 			plaintext[] = "Hi I am an AES CTR test vector distributed on 4 128-bit blocks!";
	unsigned char 	key[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
	unsigned char 	iv[16] = {0x01, 0xff, 0x83, 0xf2, 0xf9, 0x98, 0xba, 0xa4, 0xda, 0xdc, 0xaa, 0xcc, 0x8e, 0x17, 0xa4, 0x1b};
	symmetric_CTR 	ctr;
	unsigned char 	ciphertext[sizeof(plaintext)];
	unsigned char 	deciphertext[sizeof(plaintext)];
	int 			err;

	if (register_cipher(&aes_desc) == -1) {
		printf("Error: in %s, unable to register cipher\n", __func__);
		return 0;
	}

	printf("Plaintext:      \"%s\"\n", plaintext);
	printf("IV:             ");
	fprintBuffer_raw(stdout, (char*)iv, sizeof(iv));
	printf("\nKey 128:        ");
	fprintBuffer_raw(stdout, (char*)key, sizeof(key));

	/* ENCRYPT */
	if ((err = ctr_start(find_cipher("aes"), iv, key, sizeof(key), 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	if ((err = ctr_encrypt((unsigned char*)plaintext, ciphertext, sizeof(plaintext), &ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	if ((err = ctr_done(&ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	/* DECRYPT */
	if ((err = ctr_start(find_cipher("aes"), iv, key, sizeof(key), 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	if ((err = ctr_decrypt(ciphertext, deciphertext, sizeof(plaintext), &ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	if ((err = ctr_done(&ctr)) != CRYPT_OK){
		printf("ERROR: in %s, %s\n", __func__, error_to_string(err));
		return 0;
	}

	printf("\nCiphertext CTR: ");
	fprintBuffer_raw(stdout, (char*)ciphertext, sizeof(plaintext));

	if (memcmp(deciphertext, plaintext, sizeof(plaintext)) == 0){
		printf("\nRecovery:       OK\n");
	}
	else{
		printf("\nRecovery:       FAIL\n");
	}
	return 0;
}
void reg_algs(void)
{
  int err;

#ifdef RIJNDAEL
  register_cipher (&aes_desc);
#endif
#ifdef BLOWFISH
  register_cipher (&blowfish_desc);
#endif
#ifdef XTEA
  register_cipher (&xtea_desc);
#endif
#ifdef RC5
  register_cipher (&rc5_desc);
#endif
#ifdef RC6
  register_cipher (&rc6_desc);
#endif
#ifdef SAFERP
  register_cipher (&saferp_desc);
#endif
#ifdef TWOFISH
  register_cipher (&twofish_desc);
#endif
#ifdef SAFER
  register_cipher (&safer_k64_desc);
  register_cipher (&safer_sk64_desc);
  register_cipher (&safer_k128_desc);
  register_cipher (&safer_sk128_desc);
#endif
#ifdef RC2
  register_cipher (&rc2_desc);
#endif
#ifdef DES
  register_cipher (&des_desc);
  register_cipher (&des3_desc);
#endif
#ifdef CAST5
  register_cipher (&cast5_desc);
#endif
#ifdef NOEKEON
  register_cipher (&noekeon_desc);
#endif
#ifdef SKIPJACK
  register_cipher (&skipjack_desc);
#endif
#ifdef ANUBIS
  register_cipher (&anubis_desc);
#endif
#ifdef KHAZAD
  register_cipher (&khazad_desc);
#endif

#ifdef TIGER
  register_hash (&tiger_desc);
#endif
#ifdef MD2
  register_hash (&md2_desc);
#endif
#ifdef MD4
  register_hash (&md4_desc);
#endif
#ifdef MD5
  register_hash (&md5_desc);
#endif
#ifdef SHA1
  register_hash (&sha1_desc);
#endif
#ifdef SHA224
  register_hash (&sha224_desc);
#endif
#ifdef SHA256
  register_hash (&sha256_desc);
#endif
#ifdef SHA384
  register_hash (&sha384_desc);
#endif
#ifdef SHA512
  register_hash (&sha512_desc);
#endif
#ifdef RIPEMD128
  register_hash (&rmd128_desc);
#endif
#ifdef RIPEMD160
  register_hash (&rmd160_desc);
#endif
#ifdef WHIRLPOOL
  register_hash (&whirlpool_desc);
#endif
#ifdef CHC_HASH
  register_hash(&chc_desc);
  if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
     printf("chc_register error: %s\n", error_to_string(err));
     exit(EXIT_FAILURE);
  }
#endif

}