libsec.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #pragma lib "libsec.a"
  2. #pragma src "/sys/src/lib/sec"
  3. #ifndef _MPINT
  4. typedef struct mpint mpint;
  5. #endif
  6. /*
  7. * AES definitions
  8. */
  9. enum
  10. {
  11. AESbsize= 16,
  12. AESmaxkey= 32,
  13. AESmaxrounds= 14
  14. };
  15. typedef struct AESstate AESstate;
  16. struct AESstate
  17. {
  18. uint32_t setup;
  19. int rounds;
  20. int keybytes;
  21. uint8_t key[AESmaxkey]; /* unexpanded key */
  22. uint32_t ekey[4*(AESmaxrounds + 1)]; /* encryption key */
  23. uint32_t dkey[4*(AESmaxrounds + 1)]; /* decryption key */
  24. uint8_t ivec[AESbsize]; /* initialization vector */
  25. uint8_t mackey[3 * AESbsize]; /* 3 XCBC mac 96 keys */
  26. };
  27. /* block ciphers */
  28. void aes_encrypt(uint32_t rk[], int Nr, uint8_t pt[16], uint8_t ct[16]);
  29. void aes_decrypt(uint32_t rk[], int Nr, uint8_t ct[16], uint8_t pt[16]);
  30. void setupAESstate(AESstate *s, uint8_t key[], int keybytes, uint8_t *ivec);
  31. void aesCBCencrypt(uint8_t *p, int len, AESstate *s);
  32. void aesCBCdecrypt(uint8_t *p, int len, AESstate *s);
  33. void setupAESXCBCstate(AESstate *s);
  34. uint8_t* aesXCBCmac(uint8_t *p, int len, AESstate *s);
  35. typedef struct AESGCMstate AESGCMstate;
  36. struct AESGCMstate
  37. {
  38. AESstate;
  39. uint32_t H[4];
  40. uint32_t M[16][256][4];
  41. };
  42. void setupAESGCMstate(AESGCMstate *s, uint8_t *key, int keylen, uint8_t *iv, int ivlen);
  43. void aesgcm_setiv(AESGCMstate *s, uint8_t *iv, int ivlen);
  44. void aesgcm_encrypt(uint8_t *dat, uint32_t ndat, uint8_t *aad, uint32_t naad, uint8_t tag[16], AESGCMstate *s);
  45. int aesgcm_decrypt(uint8_t *dat, uint32_t ndat, uint8_t *aad, uint32_t naad, uint8_t tag[16], AESGCMstate *s);
  46. /*
  47. * Blowfish Definitions
  48. */
  49. enum
  50. {
  51. BFbsize = 8,
  52. BFrounds= 16
  53. };
  54. /* 16-round Blowfish */
  55. typedef struct BFstate BFstate;
  56. struct BFstate
  57. {
  58. uint32_t setup;
  59. uint8_t key[56];
  60. uint8_t ivec[8];
  61. uint32_t pbox[BFrounds+2];
  62. uint32_t sbox[1024];
  63. };
  64. void setupBFstate(BFstate *s, uint8_t key[], int keybytes, uint8_t *ivec);
  65. void bfCBCencrypt(uint8_t*, int, BFstate*);
  66. void bfCBCdecrypt(uint8_t*, int, BFstate*);
  67. void bfECBencrypt(uint8_t*, int, BFstate*);
  68. void bfECBdecrypt(uint8_t*, int, BFstate*);
  69. /*
  70. * Chacha definitions
  71. */
  72. enum
  73. {
  74. ChachaBsize= 64,
  75. ChachaKeylen= 256/8,
  76. ChachaIVlen= 96/8,
  77. };
  78. typedef struct Chachastate Chachastate;
  79. struct Chachastate
  80. {
  81. union{
  82. uint32_t input[16];
  83. struct {
  84. uint32_t constant[4];
  85. uint32_t key[8];
  86. uint32_t counter;
  87. uint32_t iv[3];
  88. };
  89. };
  90. int rounds;
  91. int ivwords;
  92. };
  93. void setupChachastate(Chachastate*, uint8_t*, uint32_t, uint8_t*, uint32_t, int);
  94. void chacha_setiv(Chachastate *, uint8_t*);
  95. void chacha_setblock(Chachastate*, uint64_t);
  96. void chacha_encrypt(uint8_t*, uint32_t, Chachastate*);
  97. void chacha_encrypt2(uint8_t*, uint8_t*, uint32_t, Chachastate*);
  98. void ccpoly_encrypt(uint8_t *dat, uint32_t ndat, uint8_t *aad, uint32_t naad, uint8_t tag[16], Chachastate *cs);
  99. int ccpoly_decrypt(uint8_t *dat, uint32_t ndat, uint8_t *aad, uint32_t naad, uint8_t tag[16], Chachastate *cs);
  100. /*
  101. * Salsa definitions
  102. */
  103. enum
  104. {
  105. SalsaBsize= 64,
  106. SalsaKeylen= 256/8,
  107. SalsaIVlen= 64/8,
  108. XSalsaIVlen= 192/8,
  109. };
  110. typedef struct Salsastate Salsastate;
  111. struct Salsastate
  112. {
  113. uint32_t input[16];
  114. uint32_t key[8];
  115. int rounds;
  116. int ivwords;
  117. };
  118. void setupSalsastate(Salsastate*, uint8_t*, uint32_t, uint8_t*, uint32_t, int);
  119. void salsa_setiv(Salsastate*, uint8_t*);
  120. void salsa_setblock(Salsastate*, uint64_t);
  121. void salsa_encrypt(uint8_t*, uint32_t, Salsastate*);
  122. void salsa_encrypt2(uint8_t*, uint8_t*, uint32_t, Salsastate*);
  123. void hsalsa(uint8_t h[32], uint8_t *key, uint32_t keylen, uint8_t nonce[16], int rounds);
  124. /*
  125. * DES definitions
  126. */
  127. enum
  128. {
  129. DESbsize= 8
  130. };
  131. /* single des */
  132. typedef struct DESstate DESstate;
  133. struct DESstate
  134. {
  135. uint32_t setup;
  136. uint8_t key[8]; /* unexpanded key */
  137. uint32_t expanded[32]; /* expanded key */
  138. uint8_t ivec[8]; /* initialization vector */
  139. };
  140. void setupDESstate(DESstate *s, uint8_t key[8], uint8_t *ivec);
  141. void des_key_setup(uint8_t[8], uint32_t[32]);
  142. void block_cipher(uint32_t*, uint8_t*, int);
  143. void desCBCencrypt(uint8_t*, int, DESstate*);
  144. void desCBCdecrypt(uint8_t*, int, DESstate*);
  145. void desECBencrypt(uint8_t*, int, DESstate*);
  146. void desECBdecrypt(uint8_t*, int, DESstate*);
  147. /* for backward compatibility with 7-byte DES key format */
  148. void des56to64(uint8_t *k56, uint8_t *k64);
  149. void des64to56(uint8_t *k64, uint8_t *k56);
  150. void key_setup(uint8_t[7], uint32_t[32]);
  151. /* triple des encrypt/decrypt orderings */
  152. enum {
  153. DES3E= 0,
  154. DES3D= 1,
  155. DES3EEE= 0,
  156. DES3EDE= 2,
  157. DES3DED= 5,
  158. DES3DDD= 7
  159. };
  160. typedef struct DES3state DES3state;
  161. struct DES3state
  162. {
  163. uint32_t setup;
  164. uint8_t key[3][8]; /* unexpanded key */
  165. uint32_t expanded[3][32]; /* expanded key */
  166. uint8_t ivec[8]; /* initialization vector */
  167. };
  168. void setupDES3state(DES3state *s, uint8_t key[3][8], uint8_t *ivec);
  169. void triple_block_cipher(uint32_t keys[3][32], uint8_t*, int);
  170. void des3CBCencrypt(uint8_t*, int, DES3state*);
  171. void des3CBCdecrypt(uint8_t*, int, DES3state*);
  172. void des3ECBencrypt(uint8_t*, int, DES3state*);
  173. void des3ECBdecrypt(uint8_t*, int, DES3state*);
  174. /*
  175. * digests
  176. */
  177. enum
  178. {
  179. SHA1dlen= 20, /* SHA digest length */
  180. SHA2_224dlen= 28, /* SHA-224 digest length */
  181. SHA2_256dlen= 32, /* SHA-256 digest length */
  182. SHA2_384dlen= 48, /* SHA-384 digest length */
  183. SHA2_512dlen= 64, /* SHA-512 digest length */
  184. MD4dlen= 16, /* MD4 digest length */
  185. MD5dlen= 16, /* MD5 digest length */
  186. Poly1305dlen= 16, /* Poly1305 digest length */
  187. Hmacblksz = 64, /* in bytes; from rfc2104 */
  188. };
  189. typedef struct DigestState DigestState;
  190. struct DigestState
  191. {
  192. uint64_t len;
  193. union {
  194. uint32_t state[16];
  195. uint64_t bstate[8];
  196. };
  197. uint8_t buf[256];
  198. int blen;
  199. char malloced;
  200. char seeded;
  201. };
  202. typedef struct DigestState SHAstate; /* obsolete name */
  203. typedef struct DigestState SHA1state;
  204. typedef struct DigestState SHA2_224state;
  205. typedef struct DigestState SHA2_256state;
  206. typedef struct DigestState SHA2_384state;
  207. typedef struct DigestState SHA2_512state;
  208. typedef struct DigestState MD5state;
  209. typedef struct DigestState MD4state;
  210. DigestState* md4(uint8_t*, uint32_t, uint8_t*, DigestState*);
  211. DigestState* md5(uint8_t*, uint32_t, uint8_t*, DigestState*);
  212. DigestState* sha1(uint8_t*, uint32_t, uint8_t*, DigestState*);
  213. DigestState* sha2_224(uint8_t*, uint32_t, uint8_t*, DigestState*);
  214. DigestState* sha2_256(uint8_t*, uint32_t, uint8_t*, DigestState*);
  215. DigestState* sha2_384(uint8_t*, uint32_t, uint8_t*, DigestState*);
  216. DigestState* sha2_512(uint8_t*, uint32_t, uint8_t*, DigestState*);
  217. DigestState* hmac_x(uint8_t *p, uint32_t len, uint8_t *key, uint32_t klen,
  218. uint8_t *digest, DigestState *s,
  219. DigestState*(*x)(uint8_t*, uint32_t, uint8_t*, DigestState*),
  220. int xlen);
  221. DigestState* hmac_md5(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  222. DigestState* hmac_sha1(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  223. DigestState* hmac_sha2_224(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  224. DigestState* hmac_sha2_256(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  225. DigestState* hmac_sha2_384(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  226. DigestState* hmac_sha2_512(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  227. char* md5pickle(MD5state*);
  228. MD5state* md5unpickle(char*);
  229. char* sha1pickle(SHA1state*);
  230. SHA1state* sha1unpickle(char*);
  231. DigestState* poly1305(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*);
  232. /*
  233. * random number generation
  234. */
  235. void genrandom(uint8_t *buf, int nbytes);
  236. void prng(uint8_t *buf, int nbytes);
  237. uint32_t fastrand(void);
  238. uint32_t nfastrand(uint32_t);
  239. /*
  240. * primes
  241. */
  242. void genprime(mpint *p, int n, int accuracy); /* generate n-bit probable prime */
  243. void gensafeprime(mpint *p, mpint *alpha, int n, int accuracy); /* prime & generator */
  244. void genstrongprime(mpint *p, int n, int accuracy); /* generate n-bit strong prime */
  245. void DSAprimes(mpint *q, mpint *p, uint8_t seed[SHA1dlen]);
  246. int probably_prime(mpint *n, int nrep); /* miller-rabin test */
  247. int smallprimetest(mpint *p); /* returns -1 if not prime, 0 otherwise */
  248. /*
  249. * rc4
  250. */
  251. typedef struct RC4state RC4state;
  252. struct RC4state
  253. {
  254. uint8_t state[256];
  255. uint8_t x;
  256. uint8_t y;
  257. };
  258. void setupRC4state(RC4state*, uint8_t*, int);
  259. void rc4(RC4state*, uint8_t*, int);
  260. void rc4skip(RC4state*, int);
  261. void rc4back(RC4state*, int);
  262. /*
  263. * rsa
  264. */
  265. typedef struct RSApub RSApub;
  266. typedef struct RSApriv RSApriv;
  267. typedef struct PEMChain PEMChain;
  268. /* public/encryption key */
  269. struct RSApub
  270. {
  271. mpint *n; /* modulus */
  272. mpint *ek; /* exp (encryption key) */
  273. };
  274. /* private/decryption key */
  275. struct RSApriv
  276. {
  277. RSApub pub;
  278. mpint *dk; /* exp (decryption key) */
  279. /* precomputed values to help with chinese remainder theorem calc */
  280. mpint *p;
  281. mpint *q;
  282. mpint *kp; /* dk mod p-1 */
  283. mpint *kq; /* dk mod q-1 */
  284. mpint *c2; /* (inv p) mod q */
  285. };
  286. struct PEMChain{
  287. PEMChain*next;
  288. uint8_t *pem;
  289. int pemlen;
  290. };
  291. RSApriv* rsagen(int nlen, int elen, int rounds);
  292. RSApriv* rsafill(mpint *n, mpint *e, mpint *d, mpint *p, mpint *q);
  293. mpint* rsaencrypt(RSApub *k, mpint *in, mpint *out);
  294. mpint* rsadecrypt(RSApriv *k, mpint *in, mpint *out);
  295. RSApub* rsapuballoc(void);
  296. void rsapubfree(RSApub*);
  297. RSApriv* rsaprivalloc(void);
  298. void rsaprivfree(RSApriv*);
  299. RSApub* rsaprivtopub(RSApriv*);
  300. RSApub* X509toRSApub(uint8_t*, int, char*, int);
  301. RSApriv* asn1toRSApriv(uint8_t*, int);
  302. void asn1dump(uint8_t *der, int len);
  303. uint8_t* decodePEM(char *s, char *type, int *len, char **new_s);
  304. PEMChain* decodepemchain(char *s, char *type);
  305. uint8_t* X509rsagen(RSApriv *priv, char *subj, uint32_t valid[2], int *certlen);
  306. uint8_t* X509rsareq(RSApriv *priv, char *subj, int *certlen);
  307. char* X509rsaverifydigest(uint8_t *sig, int siglen, uint8_t *edigest, int edigestlen, RSApub *pk);
  308. char* X509rsaverify(uint8_t *cert, int ncert, RSApub *pk);
  309. void X509dump(uint8_t *cert, int ncert);
  310. /*
  311. * elgamal
  312. */
  313. typedef struct EGpub EGpub;
  314. typedef struct EGpriv EGpriv;
  315. typedef struct EGsig EGsig;
  316. /* public/encryption key */
  317. struct EGpub
  318. {
  319. mpint *p; /* modulus */
  320. mpint *alpha; /* generator */
  321. mpint *key; /* (encryption key) alpha**secret mod p */
  322. };
  323. /* private/decryption key */
  324. struct EGpriv
  325. {
  326. EGpub pub;
  327. mpint *secret; /* (decryption key) */
  328. };
  329. /* signature */
  330. struct EGsig
  331. {
  332. mpint *r, *s;
  333. };
  334. EGpriv* eggen(int nlen, int rounds);
  335. mpint* egencrypt(EGpub *k, mpint *in, mpint *out); /* deprecated */
  336. mpint* egdecrypt(EGpriv *k, mpint *in, mpint *out);
  337. EGsig* egsign(EGpriv *k, mpint *m);
  338. int egverify(EGpub *k, EGsig *sig, mpint *m);
  339. EGpub* egpuballoc(void);
  340. void egpubfree(EGpub*);
  341. EGpriv* egprivalloc(void);
  342. void egprivfree(EGpriv*);
  343. EGsig* egsigalloc(void);
  344. void egsigfree(EGsig*);
  345. EGpub* egprivtopub(EGpriv*);
  346. /*
  347. * dsa
  348. */
  349. typedef struct DSApub DSApub;
  350. typedef struct DSApriv DSApriv;
  351. typedef struct DSAsig DSAsig;
  352. /* public/encryption key */
  353. struct DSApub
  354. {
  355. mpint *p; /* modulus */
  356. mpint *q; /* group order, q divides p-1 */
  357. mpint *alpha; /* group generator */
  358. mpint *key; /* (encryption key) alpha**secret mod p */
  359. };
  360. /* private/decryption key */
  361. struct DSApriv
  362. {
  363. DSApub pub;
  364. mpint *secret; /* (decryption key) */
  365. };
  366. /* signature */
  367. struct DSAsig
  368. {
  369. mpint *r, *s;
  370. };
  371. DSApriv* dsagen(DSApub *opub); /* opub not checked for consistency! */
  372. DSAsig* dsasign(DSApriv *k, mpint *m);
  373. int dsaverify(DSApub *k, DSAsig *sig, mpint *m);
  374. DSApub* dsapuballoc(void);
  375. void dsapubfree(DSApub*);
  376. DSApriv* dsaprivalloc(void);
  377. void dsaprivfree(DSApriv*);
  378. DSAsig* dsasigalloc(void);
  379. void dsasigfree(DSAsig*);
  380. DSApub* dsaprivtopub(DSApriv*);
  381. DSApriv* asn1toDSApriv(uint8_t*, int);
  382. /*
  383. * TLS
  384. */
  385. typedef struct Thumbprint{
  386. struct Thumbprint *next;
  387. uint8_t sha1[SHA1dlen];
  388. } Thumbprint;
  389. typedef struct TLSconn{
  390. char dir[40]; /* connection directory */
  391. uint8_t *cert; /* certificate (local on input, remote on output) */
  392. uint8_t *sessionID;
  393. uint8_t *psk;
  394. int certlen;
  395. int sessionIDlen;
  396. int psklen;
  397. int (*trace)(char*fmt, ...);
  398. PEMChain*chain; /* optional extra certificate evidence for servers to present */
  399. char *sessionType;
  400. uint8_t *sessionKey;
  401. int sessionKeylen;
  402. char *sessionConst;
  403. char *serverName;
  404. char *pskID;
  405. } TLSconn;
  406. /* tlshand.c */
  407. int tlsClient(int fd, TLSconn *c);
  408. int tlsServer(int fd, TLSconn *c);
  409. /* thumb.c */
  410. Thumbprint* initThumbprints(char *ok, char *crl);
  411. void freeThumbprints(Thumbprint *ok);
  412. int okThumbprint(uint8_t *sha1, Thumbprint *ok);
  413. /* readcert.c */
  414. uint8_t *readcert(char *filename, int *pcertlen);
  415. PEMChain*readcertchain(char *filename);
  416. /* aes_xts.c */
  417. int aes_xts_encrypt(uint32_t tweak[], uint32_t ecb[], int64_t sectorNumber, uint8_t *input, uint8_t *output, uint32_t len) ;
  418. int aes_xts_decrypt(uint32_t tweak[], uint32_t ecb[], int64_t sectorNumber, uint8_t *input, uint8_t *output, uint32_t len);
  419. typedef struct ECpoint{
  420. int inf;
  421. mpint *x;
  422. mpint *y;
  423. mpint *z; /* nil when using affine coordinates */
  424. } ECpoint;
  425. typedef ECpoint ECpub;
  426. typedef struct ECpriv{
  427. ECpoint;
  428. mpint *d;
  429. } ECpriv;
  430. typedef struct ECdomain{
  431. mpint *p;
  432. mpint *a;
  433. mpint *b;
  434. ECpoint G;
  435. mpint *n;
  436. mpint *h;
  437. } ECdomain;
  438. void ecdominit(ECdomain *, void (*init)(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h));
  439. void ecdomfree(ECdomain *);
  440. void ecassign(ECdomain *, ECpoint *old, ECpoint *new);
  441. void ecadd(ECdomain *, ECpoint *a, ECpoint *b, ECpoint *s);
  442. void ecmul(ECdomain *, ECpoint *a, mpint *k, ECpoint *s);
  443. ECpoint* strtoec(ECdomain *, char *, char **, ECpoint *);
  444. ECpriv* ecgen(ECdomain *, ECpriv*);
  445. int ecverify(ECdomain *, ECpoint *);
  446. int ecpubverify(ECdomain *, ECpub *);
  447. void ecdsasign(ECdomain *, ECpriv *, uint8_t *, int, mpint *, mpint *);
  448. int ecdsaverify(ECdomain *, ECpub *, uint8_t *, int, mpint *, mpint *);
  449. void base58enc(uint8_t *, char *, int);
  450. int base58dec(char *, uint8_t *, int);
  451. ECpub* ecdecodepub(ECdomain *dom, uint8_t *, int);
  452. int ecencodepub(ECdomain *dom, ECpub *, uint8_t *, int);
  453. void ecpubfree(ECpub *);
  454. ECpub* X509toECpub(uint8_t *cert, int ncert, ECdomain *dom);
  455. char* X509ecdsaverifydigest(uint8_t *sig, int siglen, uint8_t *edigest, int edigestlen, ECdomain *dom, ECpub *pub);
  456. char* X509ecdsaverify(uint8_t *sig, int siglen, ECdomain *dom, ECpub *pub);
  457. /* curves */
  458. void secp256r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
  459. void secp256k1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
  460. DigestState* ripemd160(uint8_t *, uint32_t, uint8_t *, DigestState *);
  461. /*
  462. * Diffie-Hellman key exchange
  463. */
  464. typedef struct DHstate DHstate;
  465. struct DHstate
  466. {
  467. mpint *g; /* base g */
  468. mpint *p; /* large prime */
  469. mpint *q; /* subgroup prime */
  470. mpint *x; /* random secret */
  471. mpint *y; /* public key y = g**x % p */
  472. };
  473. /* generate new public key: y = g**x % p */
  474. mpint* dh_new(DHstate *dh, mpint *p, mpint *q, mpint *g);
  475. /* calculate shared key: k = y**x % p */
  476. mpint* dh_finish(DHstate *dh, mpint *y);
  477. /* Curve25519 elliptic curve, public key function */
  478. void curve25519(uint8_t mypublic[32], uint8_t secret[32], uint8_t basepoint[32]);
  479. /* Curve25519 diffie hellman */
  480. void curve25519_dh_new(uint8_t x[32], uint8_t y[32]);
  481. void curve25519_dh_finish(uint8_t x[32], uint8_t y[32], uint8_t z[32]);
  482. /* password-based key derivation function 2 (rfc2898) */
  483. void pbkdf2_x(uint8_t *p, uint32_t plen, uint8_t *s, uint32_t slen, uint32_t rounds, uint8_t *d, uint32_t dlen,
  484. DigestState* (*x)(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*), int xlen);
  485. /* hmac-based key derivation function (rfc5869) */
  486. void hkdf_x(uint8_t *salt, uint32_t nsalt, uint8_t *info, uint32_t ninfo, uint8_t *key, uint32_t nkey, uint8_t *d, uint32_t dlen,
  487. DigestState* (*x)(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, DigestState*), int xlen);
  488. /* timing safe memcmp() */
  489. int tsmemcmp(void*, void*, uint32_t);