int main() { char **algos, **modes; int n_algos, n_modes, i_algo, i_mode; /* get consistent output even though it's "random" */ srand48(1153616166L); algos = mcrypt_list_algorithms(NULL, &n_algos); if (algos == NULL) { fprintf(stderr, "Unable to list algorithms.\n"); exit(1); } modes = mcrypt_list_modes(NULL, &n_modes); if (modes == NULL) { fprintf(stderr, "Unable to list modes.\n"); exit(1); } for (i_algo = 0; i_algo < n_algos; i_algo++) { for (i_mode = 0; i_mode < n_modes; i_mode++) { dump_testcase(algos[i_algo],modes[i_mode]); } } mcrypt_free_p(algos, n_algos); mcrypt_free_p(modes, n_modes); return 0; }
Array f_mcrypt_list_modes(CStrRef lib_dir /* = null_string */) { String dir = lib_dir.empty() ? MCG(modes_dir) : lib_dir; int count = 0; char **modules = mcrypt_list_modes((char*)dir.data(), &count); if (count == 0) { raise_warning("No modes found in module dir"); } Array ret = Array::Create(); for (int i = 0; i < count; i++) { ret.append(String(modules[i], CopyString)); } mcrypt_free_p(modules, count); return ret; }
Array HHVM_FUNCTION(mcrypt_list_algorithms, const String& lib_dir /* = null_string */) { String dir = lib_dir.empty() ? String(MCG(algorithms_dir)) : lib_dir; int count = 0; char **modules = mcrypt_list_algorithms((char*)dir.data(), &count); if (count == 0) { raise_warning("No algorithms found in module dir"); } Array ret = Array::Create(); for (int i = 0; i < count; i++) { ret.append(String(modules[i], CopyString)); } mcrypt_free_p(modules, count); return ret; }
int main() { MCRYPT td, td2; int i, t, imax; int j, jmax, ivsize; int x = 0, siz; char **names; char **modes; char *text; unsigned char *IV; unsigned char *key; int keysize; names = mcrypt_list_algorithms (ALGORITHMS_DIR, &jmax); modes = mcrypt_list_modes (MODES_DIR, &imax); if (names==NULL || modes==NULL) { fprintf(stderr, "Error getting algorithms/modes\n"); exit(1); } for (j=0;j<jmax;j++) { printf( "Algorithm: %s... ", names[j]); if (mcrypt_module_self_test( names[j], ALGORITHMS_DIR)==0) { printf( "ok\n"); } else { x=1; printf( "\n"); } printf( "Modes:\n"); for (i=0;i<imax;i++) { td = mcrypt_module_open(names[j], ALGORITHMS_DIR, modes[i], MODES_DIR); td2 = mcrypt_module_open(names[j], ALGORITHMS_DIR, modes[i], MODES_DIR); if (td != MCRYPT_FAILED && td2 != MCRYPT_FAILED) { keysize = mcrypt_enc_get_key_size(td); key = calloc(1, keysize); if (key==NULL) exit(1); for (t=0;t<keysize;t++) key[t] = (t % 255) + 13; ivsize = mcrypt_enc_get_iv_size(td); if (ivsize>0) { IV = calloc( 1, ivsize); if (IV==NULL) exit(1); for (t=0;t<ivsize;t++) IV[t] = (t*2 % 255) + 15; } if (mcrypt_generic_init( td, key, keysize, IV) < 0) { fprintf(stderr, "Failed to Initialize algorithm!\n"); return -1; } if (mcrypt_enc_is_block_mode(td)!=0) siz = (strlen(TEXT) / mcrypt_enc_get_block_size(td))*mcrypt_enc_get_block_size(td); else siz = strlen(TEXT); text = calloc( 1, siz); if (text==NULL) exit(1); memmove( text, TEXT, siz); mcrypt_generic( td, text, siz); if (mcrypt_generic_init( td2, key, keysize, IV) < 0) { fprintf(stderr, "Failed to Initialize algorithm!\n"); return -1; } mdecrypt_generic( td2, text, siz); if ( memcmp( text, TEXT, siz) == 0) { printf( " %s: ok\n", modes[i]); } else { printf( " %s: failed\n", modes[i]); x=1; } mcrypt_generic_deinit(td); mcrypt_generic_deinit(td2); mcrypt_module_close(td); mcrypt_module_close(td2); free(text); free(key); if (ivsize>0) free(IV); } } printf("\n"); } mcrypt_free_p(names, jmax); mcrypt_free_p(modes, imax); if (x>0) fprintf(stderr, "\nProbably some of the algorithms listed above failed. " "Try not to use these algorithms, and file a bug report to [email protected]\n\n"); return x; }