static int crypt_2(int *pcount, struct db_salt *salt) { int count = *pcount; int index = 0; #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index++) #endif { #if (AC_BUILT && HAVE_WHIRLPOOL) || \ (!AC_BUILT && OPENSSL_VERSION_NUMBER >= 0x10000000 && !HAVE_NO_SSL_WHIRLPOOL) WHIRLPOOL_CTX ctx; WHIRLPOOL_Init(&ctx); WHIRLPOOL_Update(&ctx, saved_key[index], strlen(saved_key[index])); WHIRLPOOL_Final((unsigned char*)crypt_out[index], &ctx); #else sph_whirlpool_context ctx; sph_whirlpool_init(&ctx); sph_whirlpool(&ctx, saved_key[index], strlen(saved_key[index])); sph_whirlpool_close(&ctx, (unsigned char*)crypt_out[index]); #endif } return count; }
ikptr ikrt_openssl_whirlpool_final (ikptr s_ctx, ikpcb * pcb) { #ifdef HAVE_WHIRLPOOL_FINAL ikptr s_pointer = IK_WHIRLPOOL_CTX_POINTER(s_ctx); WHIRLPOOL_CTX * ctx = IK_POINTER_DATA_VOIDP(s_pointer); unsigned char sum[WHIRLPOOL_DIGEST_LENGTH]; int rv = 0; if (ctx) { rv = WHIRLPOOL_Final(sum, ctx); free(ctx); IK_POINTER_SET_NULL(s_pointer); } return (rv)? ika_bytevector_from_memory_block(pcb, sum, WHIRLPOOL_DIGEST_LENGTH) : IK_FALSE; #else feature_failure(__func__); #endif }
int main (int argc,char *argv[]) { unsigned char md[WHIRLPOOL_DIGEST_LENGTH]; int i; WHIRLPOOL_CTX ctx; #ifdef OPENSSL_IA32_SSE2 /* Alternative to this is to call OpenSSL_add_all_algorithms... * The below code is retained exclusively for debugging purposes. */ { char *env; if ((env=getenv("OPENSSL_ia32cap"))) OPENSSL_ia32cap = strtoul (env,NULL,0); } #endif fprintf(stdout,"Testing Whirlpool "); WHIRLPOOL("",0,md); if (memcmp(md,iso_test_1,sizeof(iso_test_1))) { fflush(stdout); fprintf(stderr,"\nTEST 1 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL("a",1,md); if (memcmp(md,iso_test_2,sizeof(iso_test_2))) { fflush(stdout); fprintf(stderr,"\nTEST 2 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL("abc",3,md); if (memcmp(md,iso_test_3,sizeof(iso_test_3))) { fflush(stdout); fprintf(stderr,"\nTEST 3 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL("message digest",14,md); if (memcmp(md,iso_test_4,sizeof(iso_test_4))) { fflush(stdout); fprintf(stderr,"\nTEST 4 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md); if (memcmp(md,iso_test_5,sizeof(iso_test_5))) { fflush(stdout); fprintf(stderr,"\nTEST 5 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789",62,md); if (memcmp(md,iso_test_6,sizeof(iso_test_6))) { fflush(stdout); fprintf(stderr,"\nTEST 6 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890" "1234567890""1234567890""1234567890""1234567890",80,md); if (memcmp(md,iso_test_7,sizeof(iso_test_7))) { fflush(stdout); fprintf(stderr,"\nTEST 7 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md); if (memcmp(md,iso_test_8,sizeof(iso_test_8))) { fflush(stdout); fprintf(stderr,"\nTEST 8 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); WHIRLPOOL_Init (&ctx); for (i=0;i<1000000;i+=288) WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", (1000000-i)<288?1000000-i:288); WHIRLPOOL_Final (md,&ctx); if (memcmp(md,iso_test_9,sizeof(iso_test_9))) { fflush(stdout); fprintf(stderr,"\nTEST 9 of 9 failed.\n"); return 1; } else fprintf(stdout,"."); fflush(stdout); fprintf(stdout," passed.\n"); fflush(stdout); return 0; }
jbyteArray Java_ru_ivanovpv_gorets_psm_nativelib_NativeLib_generatePK( JNIEnv* env, jobject thiz, jstring password, jstring salt, jint hashType, jint keySize) { const char * saltArr = NULL; const char * passArr = NULL; const char * saltPtr = NULL; unsigned saltLength = 0; unsigned passLength = 0; unsigned char digest[MAX_HASH_SIZE]; unsigned digestSize = 0; jbyteArray byteArr = NULL; WHIRLPOOL_CTX wp_ctx; SHA512_CTX sha_ctx; if ( ((hashType != 1) && (hashType != 2)) || (keySize <= 0)) { return NULL; } digestSize = (keySize <= MAX_HASH_SIZE) ? keySize : MAX_HASH_SIZE; saltArr = (*env)->GetStringUTFChars(env, salt, NULL); if(saltArr == NULL) { return NULL; } passArr = (*env)->GetStringUTFChars(env, password, NULL); if(saltArr == NULL) { (*env)->ReleaseStringUTFChars(env, salt, saltArr); return NULL; } saltLength = (*env)->GetStringUTFLength(env, salt); passLength = (*env)->GetStringUTFLength(env, password); switch (hashType) // { case 1: // WP WHIRLPOOL_Init(&wp_ctx); saltPtr = saltArr; WHIRLPOOL_Update(&wp_ctx, (const void *)saltPtr, saltLength/2); saltPtr += saltLength/2; saltLength -= saltLength/2; WHIRLPOOL_Update(&wp_ctx, (const void *)passArr, passLength); WHIRLPOOL_Update(&wp_ctx, (const void *)saltPtr, saltLength); WHIRLPOOL_Final((unsigned char *)digest, &wp_ctx); break; case 2: // SHA512 SHA512_Init(&sha_ctx); saltPtr = saltArr; SHA512_Update(&sha_ctx, (const void *)saltPtr, saltLength/2); saltPtr += saltLength/2; saltLength -= saltLength/2; SHA512_Update(&sha_ctx, (const void *)passArr, passLength); SHA512_Update(&sha_ctx, (const void *)saltPtr, saltLength); SHA512_Final((unsigned char *)digest, &sha_ctx); break; } (*env)->ReleaseStringUTFChars(env, salt, saltArr); (*env)->ReleaseStringUTFChars(env, salt, passArr); byteArr = (*env)->NewByteArray(env, digestSize); if (byteArr == NULL) return NULL; (*env)->SetByteArrayRegion(env, byteArr, 0, digestSize, (const jbyte*)digest); memset (digest, 0, digestSize); return byteArr; }