@@ -122,6 +122,7 @@ JNIEXPORT jint JNICALL Java_org_openquantumsafe_Signature_sign
122122
123123 OQS_SIG * sig = (OQS_SIG * ) getHandle (env , obj , "native_sig_handle_" );
124124 size_t len_sig ;
125+
125126 OQS_STATUS rv_ = OQS_SIG_sign (sig , (uint8_t * )signature_native , & len_sig ,
126127 (uint8_t * )message_native , message_len ,
127128 (uint8_t * )secret_key_native );
@@ -173,3 +174,81 @@ JNIEXPORT jboolean JNICALL Java_org_openquantumsafe_Signature_verify
173174
174175 return (rv_ == OQS_SUCCESS ) ? JNI_TRUE : JNI_FALSE ;
175176}
177+
178+ /*
179+ * Class: org_openquantumsafe_Signature
180+ * Method: sign_with_ctx_str
181+ * Signature: ([BLjava/lang/Long;[BJ[B)I
182+ */
183+ JNIEXPORT jint JNICALL Java_org_openquantumsafe_Signature_sign_1with_1ctx_1str
184+ (JNIEnv * env , jobject obj , jbyteArray jsignature , jobject sig_len_obj ,
185+ jbyteArray jmessage , jlong message_len , jbyteArray jctx , jlong ctx_len ,
186+ jbyteArray jsecret_key )
187+ {
188+ // Convert to jbyte arrays
189+ jbyte * signature_native = (* env )-> GetByteArrayElements (env , jsignature , 0 );
190+ jbyte * message_native = (* env )-> GetByteArrayElements (env , jmessage , 0 );
191+ jbyte * ctx_native = (* env )-> GetByteArrayElements (env , jctx , 0 );
192+ jbyte * secret_key_native = (* env )-> GetByteArrayElements (env , jsecret_key , 0 );
193+
194+ OQS_SIG * sig = (OQS_SIG * ) getHandle (env , obj , "native_sig_handle_" );
195+ size_t len_sig ;
196+ OQS_STATUS rv_ = OQS_SIG_sign_with_ctx_str (sig , (uint8_t * )signature_native , & len_sig ,
197+ (uint8_t * )message_native , message_len ,
198+ (uint8_t * )ctx_native , ctx_len ,
199+ (uint8_t * )secret_key_native );
200+
201+ // fill java signature bytes
202+ (* env )-> SetByteArrayRegion (env , jsignature , 0 , len_sig , (jbyte * ) signature_native );
203+
204+ // fill java object signature length
205+ jfieldID value_fid = (* env )-> GetFieldID (env ,
206+ (* env )-> GetObjectClass (env , sig_len_obj ),
207+ "value" , "Ljava/lang/Object;" );
208+ jclass cls = (* env )-> FindClass (env , "java/lang/Long" );
209+ jobject jlong_obj = (* env )-> NewObject (env , cls ,
210+ (* env )-> GetMethodID (env , cls , "<init>" , "(J)V" ),
211+ (jlong ) len_sig );
212+ (* env )-> SetObjectField (env , sig_len_obj , value_fid , jlong_obj );
213+
214+ // Release C memory
215+ (* env )-> ReleaseByteArrayElements (env , jsignature , signature_native , 0 );
216+ (* env )-> ReleaseByteArrayElements (env , jmessage , message_native , JNI_ABORT );
217+ (* env )-> ReleaseByteArrayElements (env , jctx , ctx_native , JNI_ABORT );
218+ (* env )-> ReleaseByteArrayElements (env , jsecret_key , secret_key_native , JNI_ABORT );
219+
220+ return (rv_ == OQS_SUCCESS ) ? 0 : -1 ;
221+ }
222+
223+ /*
224+ * Class: org_openquantumsafe_Signature
225+ * Method: verify_with_ctx_str
226+ * Signature: ([BJ[BJ[B)Z
227+ */
228+ JNIEXPORT jboolean JNICALL Java_org_openquantumsafe_Signature_verify_1with_1ctx_1str
229+ (JNIEnv * env , jobject obj , jbyteArray jmessage , jlong message_len ,
230+ jbyteArray jsignature , jlong signature_len , jbyteArray jctx , jlong ctx_len ,
231+ jbyteArray jpublic_key )
232+ {
233+ // Convert to jbyte arrays
234+ jbyte * message_native = (* env )-> GetByteArrayElements (env , jmessage , 0 );
235+ jbyte * signature_native = (* env )-> GetByteArrayElements (env , jsignature , 0 );
236+ jbyte * ctx_native = (* env )-> GetByteArrayElements (env , jctx , 0 );
237+ jbyte * public_key_native = (* env )-> GetByteArrayElements (env , jpublic_key , 0 );
238+
239+ OQS_SIG * sig = (OQS_SIG * ) getHandle (env , obj , "native_sig_handle_" );
240+ OQS_STATUS rv_ = OQS_SIG_verify_with_ctx_str (sig , (uint8_t * ) message_native , message_len ,
241+ (uint8_t * ) signature_native , signature_len ,
242+ (uint8_t * ) ctx_native , ctx_len ,
243+ (uint8_t * ) public_key_native );
244+
245+ // Release C memory
246+ (* env )-> ReleaseByteArrayElements (env , jsignature , signature_native , JNI_ABORT );
247+ (* env )-> ReleaseByteArrayElements (env , jmessage , message_native , JNI_ABORT );
248+ (* env )-> ReleaseByteArrayElements (env , jctx , ctx_native , JNI_ABORT );
249+ (* env )-> ReleaseByteArrayElements (env , jpublic_key , public_key_native , JNI_ABORT );
250+
251+ return (rv_ == OQS_SUCCESS ) ? JNI_TRUE : JNI_FALSE ;
252+ }
253+
254+
0 commit comments