@@ -20,6 +20,7 @@ class KeyEncapsulationDetails {
2020 long length_secret_key ;
2121 long length_ciphertext ;
2222 long length_shared_secret ;
23+ long length_keypair_seed ;
2324
2425 /**
2526 * \brief Print KEM algorithm details
@@ -33,7 +34,9 @@ void printKeyEncapsulation() {
3334 "\n Length public key (bytes): " + this .length_public_key +
3435 "\n Length secret key (bytes): " + this .length_secret_key +
3536 "\n Length ciphertext (bytes): " + this .length_ciphertext +
36- "\n Length shared secret (bytes): " + this .length_shared_secret
37+ "\n Length shared secret (bytes): " + this .length_shared_secret +
38+ "\n Length keypair seed (bytes): "
39+ + (this .length_keypair_seed > 0 ) ? this .length_keypair_seed : "N/A"
3740 );
3841 }
3942
@@ -114,6 +117,18 @@ public KeyEncapsulation(String alg_name, byte[] secret_key)
114117 */
115118 private native int generate_keypair (byte [] public_key , byte [] secret_key );
116119
120+ /**
121+ * \brief Wrapper for OQS_API OQS_STATUS OQS_KEM_keypair_derand(const OQS_KEM *kem,
122+ * uint8_t *public_key, uint8_t *secret_key,
123+ * const uint8_t *seed);
124+ * \param Public key
125+ * \param Secret key
126+ * \param Seed
127+ * \return Status
128+ */
129+ private native int generate_keypair_derand (byte [] public_key ,
130+ byte [] secret_key , byte [] seed );
131+
117132 /**
118133 * \brief Wrapper for OQS_API OQS_STATUS OQS_KEM_encaps(const OQS_KEM *kem,
119134 * uint8_t *ciphertext,
@@ -159,6 +174,27 @@ public byte[] generate_keypair() throws RuntimeException {
159174 return this .public_key_ ;
160175 }
161176
177+ /**
178+ * \brief Invoke native generate_keypair_derand method using the PK and SK lengths
179+ * from alg_details_. Check return value and if != 0 throw Exception.
180+ */
181+ public byte [] generate_keypair (byte [] seed ) throws RuntimeException {
182+ if (seed .length != alg_details_ .length_keypair_seed ) {
183+ throw new RuntimeException ("Incorrect seed length" );
184+ }
185+
186+ int rv_ = generate_keypair_derand (this .public_key_ , this .secret_key_ , seed );
187+ if (rv_ != 0 ) throw new RuntimeException ("Cannot generate keypair from seed" );
188+ return this .public_key_ ;
189+ }
190+
191+ /**
192+ * \brief Return seed length
193+ */
194+ public long get_keypair_seed_length () {
195+ return alg_details_ .length_keypair_seed ;
196+ }
197+
162198 /**
163199 * \brief Return public key
164200 */
0 commit comments