Example #1
0
void fpm_cipher_init(char *cipher_name) {

    if(strcmp(cipher_name, "BLOWFISH") == 0) {
	cipher_algo = BLOWFISH;
    }
    else if(strcmp(cipher_name, "AES-256") == 0) {
	cipher_algo = AES256;
    }

    switch(cipher_algo)  {
	case BLOWFISH:
		if (strcmp("BLOWFISH", blowfish_get_info(4, &keylen, &blocksize,
					     &contextsize, &fpm_setkey,
					     &fpm_encrypt_block,
					     &fpm_decrypt_block)))
		{ g_assert_not_reached(); }
		break;
	case AES256:
		if (strcmp("AES256", rijndael_get_info(9, &keylen, &blocksize,
					     &contextsize, &fpm_setkey,
					     &fpm_encrypt_block,
					     &fpm_decrypt_block)))
		{ g_assert_not_reached(); }
		break;
	default:
		printf("Unknown cipher algorithm!\n");
		exit(-1);
    }
    cipher->name = ciphers[cipher_algo].name;
    cipher->hash_len = ciphers[cipher_algo].hash_len;
    cipher->salt_len = ciphers[cipher_algo].salt_len;
    cipher->keylen = keylen;
    cipher->blocksize = blocksize;
    cipher->contextsize = contextsize;
}
/****************
 * Put the static entries into the table.
 */
static void
setup_cipher_table(void)
{
    int i=0;

#ifdef USE_AES
    cipher_table[i].algo = CIPHER_ALGO_AES;
    cipher_table[i].name = rijndael_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
    cipher_table[i].algo = CIPHER_ALGO_AES192;
    cipher_table[i].name = rijndael_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
    cipher_table[i].algo = CIPHER_ALGO_AES256;
    cipher_table[i].name = rijndael_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
#endif

#ifdef USE_TWOFISH
    cipher_table[i].algo = CIPHER_ALGO_TWOFISH;
    cipher_table[i].name = twofish_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
#endif

#ifdef USE_BLOWFISH
    cipher_table[i].algo = CIPHER_ALGO_BLOWFISH;
    cipher_table[i].name = blowfish_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
#endif

#ifdef USE_CAST5
    cipher_table[i].algo = CIPHER_ALGO_CAST5;
    cipher_table[i].name = cast5_get_info( cipher_table[i].algo,
                                           &cipher_table[i].keylen,
                                           &cipher_table[i].blocksize,
                                           &cipher_table[i].contextsize,
                                           &cipher_table[i].setkey,
                                           &cipher_table[i].encrypt,
                                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
#endif

    cipher_table[i].algo = CIPHER_ALGO_3DES;
    cipher_table[i].name = des_get_info( cipher_table[i].algo,
                                         &cipher_table[i].keylen,
                                         &cipher_table[i].blocksize,
                                         &cipher_table[i].contextsize,
                                         &cipher_table[i].setkey,
                                         &cipher_table[i].encrypt,
                                         &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;

#ifdef USE_CAMELLIA
    cipher_table[i].algo = CIPHER_ALGO_CAMELLIA128;
    cipher_table[i].name = camellia_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
    cipher_table[i].algo = CIPHER_ALGO_CAMELLIA256;
    cipher_table[i].name = camellia_get_info( cipher_table[i].algo,
                           &cipher_table[i].keylen,
                           &cipher_table[i].blocksize,
                           &cipher_table[i].contextsize,
                           &cipher_table[i].setkey,
                           &cipher_table[i].encrypt,
                           &cipher_table[i].decrypt     );
    if( !cipher_table[i].name )
        BUG();
    i++;
#endif

#ifdef USE_IDEA
    cipher_table[i].algo = CIPHER_ALGO_IDEA;
    cipher_table[i].name = idea_get_info( cipher_table[i].algo,
                                          &cipher_table[i].keylen,
                                          &cipher_table[i].blocksize,
                                          &cipher_table[i].contextsize,
                                          &cipher_table[i].setkey,
                                          &cipher_table[i].encrypt,
                                          &cipher_table[i].decrypt     );
    if (cipher_table[i].name)
        i++;  /* Note that the loadable IDEA module may not be
	       available. */
#endif

#ifdef ALLOW_DUMMY
    cipher_table[i].algo = CIPHER_ALGO_DUMMY;
    cipher_table[i].name = "DUMMY";
    cipher_table[i].blocksize = 8;
    cipher_table[i].keylen = 128;
    cipher_table[i].contextsize = 0;
    cipher_table[i].setkey = dummy_setkey;
    cipher_table[i].encrypt = dummy_encrypt_block;
    cipher_table[i].decrypt = dummy_decrypt_block;
    i++;
#endif

    for( ; i < TABLE_SIZE; i++ )
        cipher_table[i].name = NULL;
}