x_bn = BN_new();
if (x_bn == NULL) {
+ njs_webcrypto_error(vm, "BN_new() failed");
goto fail;
}
y_bn = BN_new();
if (y_bn == NULL) {
+ njs_webcrypto_error(vm, "BN_new() failed");
goto fail;
}
static BIGNUM *
njs_import_base64url_bignum(njs_vm_t *vm, njs_opaque_value_t *value)
{
+ BIGNUM *bn;
njs_int_t ret;
njs_str_t data, decoded;
u_char buf[512];
njs_decode_base64url(&decoded, &data);
- return BN_bin2bn(decoded.start, decoded.length, NULL);
+ bn = BN_bin2bn(decoded.start, decoded.length, NULL);
+ if (njs_slow_path(bn == NULL)) {
+ njs_webcrypto_error(vm, "BN_bin2bn() failed");
+ }
+
+ return bn;
}
pkey = EVP_PKEY_new();
if (njs_slow_path(pkey == NULL)) {
+ njs_webcrypto_error(vm, "EVP_PKEY_new() failed");
goto fail;
}
if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
+ njs_webcrypto_error(vm, "EVP_PKEY_set1_RSA() failed");
EVP_PKEY_free(pkey);
goto fail;
}
pkey = EVP_PKEY_new();
if (njs_slow_path(pkey == NULL)) {
+ njs_webcrypto_error(vm, "EVP_PKEY_new() failed");
goto fail;
}
n = njs_ec_rs_size(pkey);
if (n == 0) {
+ njs_webcrypto_error(vm, "cannot determine ECDSA signature length");
goto fail;
}
ec_sig = d2i_ECDSA_SIG(NULL, &der, der_len);
if (ec_sig == NULL) {
+ njs_webcrypto_error(vm, "d2i_ECDSA_SIG() failed");
goto fail;
}
#endif
if (njs_bn_bn2binpad(r, data, n) <= 0) {
+ njs_webcrypto_error(vm, "njs_bn_bn2binpad() failed");
goto fail;
}
if (njs_bn_bn2binpad(s, &data[n], n) <= 0) {
+ njs_webcrypto_error(vm, "njs_bn_bn2binpad() failed");
goto fail;
}
fail:
- *out_len = 0;
+ ret = NJS_ERROR;
done:
x_bn = BN_new();
if (x_bn == NULL) {
+ qjs_webcrypto_error(cx, "BN_new() failed");
goto fail;
}
y_bn = BN_new();
if (y_bn == NULL) {
+ qjs_webcrypto_error(cx, "BN_new() failed");
goto fail;
}
bn = BN_bin2bn(decoded.start, decoded.length, NULL);
JS_FreeCString(cx, (char *) data.start);
+ if (bn == NULL) {
+ qjs_webcrypto_error(cx, "BN_bin2bn() failed");
+ }
+
return bn;
}
pkey = EVP_PKEY_new();
if (pkey == NULL) {
+ qjs_webcrypto_error(cx, "EVP_PKEY_new() failed");
goto fail;
}
if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
+ qjs_webcrypto_error(cx, "EVP_PKEY_set1_RSA() failed");
EVP_PKEY_free(pkey);
goto fail;
}
pkey = EVP_PKEY_new();
if (pkey == NULL) {
+ qjs_webcrypto_error(cx, "EVP_PKEY_new() failed");
goto fail;
}
x_str = JS_ToCStringLen(cx, &x_len, val);
JS_FreeValue(cx, val);
+ if (x_str == NULL) {
+ return NULL;
+ }
+
x_b64.start = (u_char *) x_str;
x_b64.length = x_len;
x_raw.start = x_buf;
d_str = JS_ToCStringLen(cx, &d_len, val);
JS_FreeValue(cx, val);
+ if (d_str == NULL) {
+ return NULL;
+ }
+
d_b64.start = (u_char *) d_str;
d_b64.length = d_len;
d_raw.start = d_buf;
n = qjs_ec_rs_size(pkey);
if (n == 0) {
+ qjs_webcrypto_error(cx, "cannot determine ECDSA signature length");
return -1;
}
ec_sig = d2i_ECDSA_SIG(NULL, &der, der_len);
if (ec_sig == NULL) {
+ qjs_webcrypto_error(cx, "d2i_ECDSA_SIG() failed");
goto fail;
}
#endif
if (njs_bn_bn2binpad(r, data, n) <= 0) {
+ qjs_webcrypto_error(cx, "njs_bn_bn2binpad() failed");
goto fail;
}
if (njs_bn_bn2binpad(s, &data[n], n) <= 0) {
+ qjs_webcrypto_error(cx, "njs_bn_bn2binpad() failed");
goto fail;
}