77 if (pass && passlen < 0)
78 passlen = strlen((
char *)pass);
84 int iter,
int wrap_nid,
int pbe_nid,
123 encalg = X509_ALGOR_new();
190 X509_ALGOR_free(encalg);
215 X509_ALGOR_free(encalg);
224 static int kek_unwrap_key(
unsigned char *out,
size_t *outlen,
230 if (inlen < 2 * blocklen)
235 if (inlen % blocklen)
243 in + inlen - 2 * blocklen, blocklen * 2);
249 tmp + inlen - blocklen, blocklen);
258 if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff)
263 if (inlen < (
size_t)(tmp[0] - 4 ))
268 *outlen = (size_t)tmp[0];
269 memcpy(out, tmp + 4, *outlen);
278 static int kek_wrap_key(
unsigned char *out,
size_t *outlen,
287 olen = (inlen + 4 + blocklen - 1)/blocklen;
289 if (olen < 2 * blocklen)
302 out[0] = (
unsigned char)inlen;
303 out[1] = in[0] ^ 0xFF;
304 out[2] = in[1] ^ 0xFF;
305 out[3] = in[2] ^ 0xFF;
306 memcpy(out + 4, in, inlen);
308 if (olen > inlen + 4)
327 const unsigned char *
p = NULL;
333 unsigned char *
key = NULL;
359 kekalg = d2i_X509_ALGOR(NULL, &p, plen);
405 if (!kek_wrap_key(NULL, &keylen, ec->
key, ec->
keylen, &kekctx))
413 if (!kek_wrap_key(key, &keylen, ec->
key, ec->
keylen, &kekctx))
428 if (!kek_unwrap_key(key, &keylen,
450 X509_ALGOR_free(kekalg);