s2n_rsa.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. #include <openssl/rsa.h>
  17. #include <stdint.h>
  18. #include "api/s2n.h"
  19. #include "crypto/s2n_hash.h"
  20. #include "utils/s2n_blob.h"
  21. /* Forward declaration to avoid the circular dependency with s2n_pkey.h */
  22. struct s2n_pkey;
  23. struct s2n_rsa_key {
  24. /*
  25. * Starting in openssl_3, `EVP_PKEY_get1_RSA` and `EVP_PKEY_get0_RSA` functions
  26. * return a pre-cached copy of the underlying key. This means that any mutations
  27. * are not reflected back onto the underlying key.
  28. *
  29. * The `const` identifier is present to help ensure that the key is not mutated.
  30. * Usecases which require a non-const RSA key (some openssl functions), should
  31. * use `s2n_unsafe_rsa_get_non_const` while ensuring that the usage is safe.
  32. */
  33. const RSA *rsa;
  34. };
  35. RSA *s2n_unsafe_rsa_get_non_const(const struct s2n_rsa_key *rsa_key);
  36. typedef struct s2n_rsa_key s2n_rsa_public_key;
  37. typedef struct s2n_rsa_key s2n_rsa_private_key;
  38. int s2n_rsa_pkey_init(struct s2n_pkey *pkey);
  39. int s2n_evp_pkey_to_rsa_public_key(s2n_rsa_public_key *rsa_key, EVP_PKEY *pkey);
  40. int s2n_evp_pkey_to_rsa_private_key(s2n_rsa_private_key *rsa_key, EVP_PKEY *pkey);