s2n_ecdsa.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/ecdsa.h>
  17. #include <stdint.h>
  18. #include "api/s2n.h"
  19. #include "crypto/s2n_ecc_evp.h"
  20. #include "crypto/s2n_hash.h"
  21. #include "stuffer/s2n_stuffer.h"
  22. #include "utils/s2n_blob.h"
  23. /* Forward declaration to avoid the circular dependency with s2n_pkey.h */
  24. struct s2n_pkey;
  25. struct s2n_ecdsa_key {
  26. /*
  27. * Starting in openssl_3, `EVP_PKEY_get1_EC_KEY` and `EVP_PKEY_get0_EC_KEY`
  28. * functions return a pre-cached copy of the underlying key. This means that any
  29. * mutations are not reflected back onto the underlying key.
  30. *
  31. * The `const` identifier is present to help ensure that the key is not mutated.
  32. * Usecases which require a non-const EC_KEY (some openssl functions), should
  33. * use `s2n_unsafe_ecdsa_get_non_const` while ensuring that the usage is safe.
  34. */
  35. const EC_KEY *ec_key;
  36. };
  37. typedef struct s2n_ecdsa_key s2n_ecdsa_public_key;
  38. typedef struct s2n_ecdsa_key s2n_ecdsa_private_key;
  39. int s2n_ecdsa_pkey_init(struct s2n_pkey *pkey);
  40. int s2n_ecdsa_pkey_matches_curve(const struct s2n_ecdsa_key *ecdsa_key, const struct s2n_ecc_named_curve *curve);
  41. int s2n_evp_pkey_to_ecdsa_public_key(s2n_ecdsa_public_key *ecdsa_key, EVP_PKEY *pkey);
  42. int s2n_evp_pkey_to_ecdsa_private_key(s2n_ecdsa_private_key *ecdsa_key, EVP_PKEY *pkey);