@@ -119,6 +119,53 @@ internal bool ml_keygen(out byte[] pk, out byte[] sk, byte[] seed = null) {
119
119
return true ;
120
120
}
121
121
122
+ internal bool ml_derive_public ( byte [ ] sk , out byte [ ] pk ) {
123
+ byte [ ] tr ;
124
+ byte [ ] rho ;
125
+ byte [ ] key ;
126
+ PolyVecL [ ] mat ;
127
+ PolyVecL s1 , s1hat ;
128
+ PolyVecK s2 , t1 , t0 ;
129
+
130
+ mat = new PolyVecL [ K ] ;
131
+ for ( int i = 0 ; i < K ; i ++ ) {
132
+ mat [ i ] = new PolyVecL ( L , N ) ;
133
+ }
134
+
135
+ rho = new byte [ ( 2 * SeedBytes ) + CrhBytes ] ;
136
+ tr = new byte [ TrBytes ] ;
137
+ key = new byte [ SeedBytes ] ;
138
+ t0 = new PolyVecK ( K , N ) ;
139
+ s1 = new PolyVecL ( L , N ) ;
140
+ s2 = new PolyVecK ( K , N ) ;
141
+
142
+ /* unpack the private key */
143
+ unpack_sk ( rho , tr , key , t0 , s1 , s2 , sk ) ;
144
+
145
+ /* Expand matrix */
146
+ polyvec_matrix_expand ( mat , rho ) ;
147
+
148
+ /* Matrix-vector multiplication */
149
+ t0 = new PolyVecK ( K , N ) ;
150
+ t1 = new PolyVecK ( K , N ) ;
151
+ s1hat = s1 . Clone ( ) ;
152
+ polyvecl_ntt ( s1hat ) ;
153
+ polyvec_matrix_pointwise_montgomery ( t1 , mat , s1hat ) ;
154
+ polyveck_reduce ( t1 ) ;
155
+ polyveck_invntt_tomont ( t1 ) ;
156
+
157
+ /* Add error vector s2 */
158
+ polyveck_add ( t1 , t1 , s2 ) ;
159
+
160
+ /* Extract t1 and write public key */
161
+ polyveck_caddq ( t1 ) ;
162
+ polyveck_power2round ( t1 , t0 , t1 ) ;
163
+ pk = new byte [ PublicKeyBytes ] ;
164
+ pack_pk ( pk , rho , t1 ) ;
165
+
166
+ return true ;
167
+ }
168
+
122
169
/*************************************************
123
170
* Name: crypto_sign_signature_internal
124
171
*
0 commit comments