• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <openssl/rsa.h>
11 
12 #include <assert.h>
13 
14 #include <openssl/bn.h>
15 
16 
RSA_generate_key(int bits,uint64_t e_value,void * callback,void * cb_arg)17 RSA *RSA_generate_key(int bits, uint64_t e_value, void *callback,
18                       void *cb_arg) {
19   assert(callback == NULL);
20   assert(cb_arg == NULL);
21 
22   RSA *rsa = RSA_new();
23   BIGNUM *e = BN_new();
24 
25   if (rsa == NULL ||
26       e == NULL ||
27       !BN_set_u64(e, e_value) ||
28       !RSA_generate_key_ex(rsa, bits, e, NULL)) {
29     goto err;
30   }
31 
32   BN_free(e);
33   return rsa;
34 
35 err:
36   BN_free(e);
37   RSA_free(rsa);
38   return NULL;
39 }
40 
RSA_padding_add_PKCS1_PSS(const RSA * rsa,uint8_t * EM,const uint8_t * mHash,const EVP_MD * Hash,int sLen)41 int RSA_padding_add_PKCS1_PSS(const RSA *rsa, uint8_t *EM, const uint8_t *mHash,
42                               const EVP_MD *Hash, int sLen) {
43   return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, NULL, sLen);
44 }
45 
RSA_verify_PKCS1_PSS(const RSA * rsa,const uint8_t * mHash,const EVP_MD * Hash,const uint8_t * EM,int sLen)46 int RSA_verify_PKCS1_PSS(const RSA *rsa, const uint8_t *mHash,
47                          const EVP_MD *Hash, const uint8_t *EM, int sLen) {
48   return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, NULL, EM, sLen);
49 }
50 
RSA_padding_add_PKCS1_OAEP(uint8_t * to,size_t to_len,const uint8_t * from,size_t from_len,const uint8_t * param,size_t param_len)51 int RSA_padding_add_PKCS1_OAEP(uint8_t *to, size_t to_len,
52                                const uint8_t *from, size_t from_len,
53                                const uint8_t *param, size_t param_len) {
54   return RSA_padding_add_PKCS1_OAEP_mgf1(to, to_len, from, from_len, param,
55                                          param_len, NULL, NULL);
56 }
57