MCPcopy Index your code
hub / github.com/SeanDragon/protools / KDF

Method KDF

security/src/main/java/pro/tools/security/sm/SM2.java:159–179  ·  view source on GitHub ↗

密钥派生函数 @param Z @param klen 生成klen字节数长度的密钥 @return

(byte[] Z, int klen)

Source from the content-addressed store, hash-verified

157 * @return
158 */
159 private static byte[] KDF(byte[] Z, int klen) {
160 int ct = 1;
161 int end = (int) Math.ceil(klen * 1.0 / 32);
162 ByteArrayOutputStream baos = new ByteArrayOutputStream();
163 try {
164 for (int i = 1; i < end; i++) {
165 baos.write(sm3hash(Z, SM3.toByteArray(ct)));
166 ct++;
167 }
168 byte[] last = sm3hash(Z, SM3.toByteArray(ct));
169 if (klen % 32 == 0) {
170 baos.write(last);
171 } else {
172 baos.write(last, 0, klen % 32);
173 }
174 return baos.toByteArray();
175 } catch (Exception e) {
176 e.printStackTrace();
177 }
178 return null;
179 }
180
181 /**
182 * 判断字节数组是否全0

Callers 4

encryptMethod · 0.95
decryptMethod · 0.95
keyExchange_2Method · 0.80
keyExchange_3Method · 0.80

Calls 3

sm3hashMethod · 0.95
toByteArrayMethod · 0.95
writeMethod · 0.80

Tested by

no test coverage detected