@@ -23,6 +23,33 @@ private static byte[] copy(byte[] of) {
2323 return Arrays .copyOf (of , of .length );
2424 }
2525
26+ private static void cryptoSignKeyPairTest (int nRound ) {
27+ for (int iRound = 0 ; iRound < nRound ; iRound ++) {
28+ byte [] javaPublicKey = new byte [32 ];
29+ byte [] javaSecretKey = new byte [64 ];
30+ byte [] cPublicKey = new byte [32 ];
31+ byte [] cSecretKey = new byte [64 ];
32+
33+ boolean isSeeded = true ;
34+ prng .nextBytes (javaSecretKey );
35+ System .arraycopy (javaSecretKey , 0 , cSecretKey , 0 , javaSecretKey .length );
36+
37+ TweetNaCl .crypto_sign_keypair (javaPublicKey , javaSecretKey , isSeeded );
38+
39+ int jniRc = JniTweetNacl .crypto_sign_keypair (cPublicKey , cSecretKey );
40+ if (jniRc != 0 )
41+ throw new IllegalStateException ("non-zero jni return code " + jniRc );
42+
43+ if (!Arrays .equals (javaSecretKey , cSecretKey ))
44+ throw new IllegalStateException ("Java secret key != C secret key!" );
45+
46+ if (!Arrays .equals (javaPublicKey , cPublicKey ))
47+ throw new IllegalStateException ("JNI unsign != original!" );
48+
49+ assertTrue ("crypto sign-keypair round " + iRound , Arrays .equals (javaSecretKey , cSecretKey ));
50+ }
51+ }
52+
2653 private static void cryptoSignOpenTest (int nRound , int messageLength ) {
2754 byte [] publicKey = new byte [32 ];
2855 byte [] secretKey = new byte [64 ];
@@ -183,6 +210,7 @@ private static void cryptoBoxOpenTest(int nRound, int messageLength) {
183210 int size = (int ) Math .pow (2 , exp );
184211 size += prng .nextInt (size );
185212
213+ cryptoSignKeyPairTest (N_ROUND );
186214 cryptoBoxTest (N_ROUND , size );
187215 cryptoBoxOpenTest (N_ROUND , size );
188216 cryptoSignTest (N_ROUND , size );
0 commit comments