| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/rsa.h> |
| 16 |
| 17 | #include <assert.h> |
| 18 |
| 19 | #include <openssl/bn.h> |
| 20 |
| 21 |
| 22 | RSA *RSA_generate_key(int bits, uint64_t e_value, void *callback, |
| 23 | void *cb_arg) { |
| 24 | assert(callback == NULL); |
| 25 | assert(cb_arg == NULL); |
| 26 |
| 27 | RSA *rsa = RSA_new(); |
| 28 | BIGNUM *e = BN_new(); |
| 29 |
| 30 | if (rsa == NULL || |
| 31 | e == NULL || |
| 32 | !BN_set_u64(e, e_value) || |
| 33 | !RSA_generate_key_ex(rsa, bits, e, NULL)) { |
| 34 | goto err; |
| 35 | } |
| 36 |
| 37 | BN_free(e); |
| 38 | return rsa; |
| 39 |
| 40 | err: |
| 41 | BN_free(e); |
| 42 | RSA_free(rsa); |
| 43 | return NULL; |
| 44 | } |
| 45 |
| 46 | int RSA_padding_add_PKCS1_PSS(const RSA *rsa, uint8_t *EM, const uint8_t *mHash, |
| 47 | const EVP_MD *Hash, int sLen) { |
| 48 | return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, NULL, sLen); |
| 49 | } |
| 50 |
| 51 | int RSA_verify_PKCS1_PSS(const RSA *rsa, const uint8_t *mHash, |
| 52 | const EVP_MD *Hash, const uint8_t *EM, int sLen) { |
| 53 | return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, NULL, EM, sLen); |
| 54 | } |
| 55 |
| 56 | int RSA_padding_add_PKCS1_OAEP(uint8_t *to, size_t to_len, |
| 57 | const uint8_t *from, size_t from_len, |
| 58 | const uint8_t *param, size_t param_len) { |
| 59 | return RSA_padding_add_PKCS1_OAEP_mgf1(to, to_len, from, from_len, param, |
| 60 | param_len, NULL, NULL); |
| 61 | } |
| 62 |