@@ -44,10 +44,16 @@ JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeProvider_
44
44
init_classes (env , "Nettle" );
45
45
46
46
yarrow256_init (& yarrow , 0 , NULL );
47
- uint8_t file = open ("/dev/random" , O_RDONLY );
48
- yarrow256_seed (& yarrow , YARROW256_SEED_FILE_SIZE , & file );
49
- close (file );
50
-
47
+ FILE * urandom = fopen ("/dev/urandom" , "rb" );
48
+ uint8_t seed [YARROW256_SEED_FILE_SIZE ];
49
+ if (urandom ) {
50
+ size_t read = 0 ;
51
+ while (read < sizeof (seed )) {
52
+ read += fread (((uint8_t * )& seed ) + read , 1 , sizeof (seed ) - read , urandom );
53
+ }
54
+ fclose (urandom );
55
+ }
56
+ yarrow256_seed (& yarrow , YARROW256_SEED_FILE_SIZE , seed );
51
57
}
52
58
53
59
JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_NettleLib_getCurves (JNIEnv * env , jobject self ) {
@@ -66,6 +72,24 @@ JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_NettleLib_getCur
66
72
return result ;
67
73
}
68
74
75
+ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_NettleLib_supportsDeterministicPRNG (JNIEnv * env , jobject self ) {
76
+ return JNI_TRUE ;
77
+ }
78
+
79
+ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_NettleLib_setupDeterministicPRNG (JNIEnv * env , jobject self , jbyteArray seed ) {
80
+ jsize seed_length = (* env )-> GetArrayLength (env , seed );
81
+ if (seed_length < YARROW256_SEED_FILE_SIZE ) {
82
+ fprintf (stderr , "Error setting seed, needs to be at least %i bytes.\n" , YARROW256_SEED_FILE_SIZE );
83
+ return JNI_FALSE ;
84
+ }
85
+
86
+ jbyte * seed_data = (* env )-> GetByteArrayElements (env , seed , NULL );
87
+ yarrow256_init (& yarrow , 0 , NULL );
88
+ yarrow256_seed (& yarrow , YARROW256_SEED_FILE_SIZE , seed_data );
89
+ (* env )-> ReleaseByteArrayElements (env , seed , seed_data , JNI_ABORT );
90
+ return JNI_TRUE ;
91
+ }
92
+
69
93
static const struct ecc_curve * create_curve_from_name (JNIEnv * env , const char * curve_name ) {
70
94
if (!curve_name ) {
71
95
return NULL ;
0 commit comments