/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#include <string.h>
#include "rsa_locl.h"
+#include <openssl/err.h>
RSA_METHOD *RSA_meth_new(const char *name, int flags)
{
- RSA_METHOD *meth = OPENSSL_zalloc(sizeof(RSA_METHOD));
+ RSA_METHOD *meth = OPENSSL_zalloc(sizeof(*meth));
if (meth != NULL) {
- meth->name = OPENSSL_strdup(name);
meth->flags = flags;
+
+ meth->name = OPENSSL_strdup(name);
+ if (meth->name != NULL)
+ return meth;
+
+ OPENSSL_free(meth);
}
- return meth;
+ RSAerr(RSA_F_RSA_METH_NEW, ERR_R_MALLOC_FAILURE);
+ return NULL;
}
void RSA_meth_free(RSA_METHOD *meth)
{
if (meth != NULL) {
- if (meth->name != NULL)
- OPENSSL_free(meth->name);
+ OPENSSL_free(meth->name);
OPENSSL_free(meth);
}
}
RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
{
- RSA_METHOD *ret;
-
- ret = OPENSSL_malloc(sizeof(RSA_METHOD));
+ RSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
if (ret != NULL) {
memcpy(ret, meth, sizeof(*meth));
+
ret->name = OPENSSL_strdup(meth->name);
+ if (ret->name != NULL)
+ return ret;
+
+ OPENSSL_free(ret);
}
- return ret;
+ RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE);
+ return NULL;
}
const char *RSA_meth_get0_name(const RSA_METHOD *meth)
int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
{
+ char *tmpname = OPENSSL_strdup(name);
+
+ if (tmpname == NULL) {
+ RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+
OPENSSL_free(meth->name);
- meth->name = OPENSSL_strdup(name);
+ meth->name = tmpname;
- return meth->name != NULL;
+ return 1;
}
-int RSA_meth_get_flags(RSA_METHOD *meth)
+int RSA_meth_get_flags(const RSA_METHOD *meth)
{
return meth->flags;
}
/* Can be null */
int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
- (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
+ (BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx)
{
return meth->rsa_mod_exp;
}
int RSA_meth_set_mod_exp(RSA_METHOD *meth,
- int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
+ int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
BN_CTX *ctx))
{
meth->rsa_mod_exp = mod_exp;
return 1;
}
+int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth))
+ (RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb)
+{
+ return meth->rsa_multi_prime_keygen;
+}
+
+int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
+ int (*keygen) (RSA *rsa, int bits,
+ int primes, BIGNUM *e,
+ BN_GENCB *cb))
+{
+ meth->rsa_multi_prime_keygen = keygen;
+ return 1;
+}