n_pkey.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. #include <openssl/opensslconf.h>
  10. #include "internal/cryptlib.h"
  11. #include <stdio.h>
  12. #include <openssl/rsa.h>
  13. #include <openssl/objects.h>
  14. #include <openssl/asn1t.h>
  15. #include <openssl/evp.h>
  16. #include <openssl/x509.h>
  17. #define ASN1_BROKEN_SEQUENCE(tname) \
  18. static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
  19. ASN1_SEQUENCE(tname)
  20. #define static_ASN1_BROKEN_SEQUENCE_END(stname) \
  21. static_ASN1_SEQUENCE_END_ref(stname, stname)
  22. typedef struct netscape_pkey_st {
  23. int32_t version;
  24. X509_ALGOR *algor;
  25. ASN1_OCTET_STRING *private_key;
  26. } NETSCAPE_PKEY;
  27. typedef struct netscape_encrypted_pkey_st {
  28. ASN1_OCTET_STRING *os;
  29. /*
  30. * This is the same structure as DigestInfo so use it: although this
  31. * isn't really anything to do with digests.
  32. */
  33. X509_SIG *enckey;
  34. } NETSCAPE_ENCRYPTED_PKEY;
  35. ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
  36. ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING),
  37. ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
  38. } static_ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
  39. DECLARE_ASN1_FUNCTIONS(NETSCAPE_ENCRYPTED_PKEY)
  40. DECLARE_ASN1_ENCODE_FUNCTIONS_name(NETSCAPE_ENCRYPTED_PKEY, NETSCAPE_ENCRYPTED_PKEY)
  41. IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_ENCRYPTED_PKEY)
  42. ASN1_SEQUENCE(NETSCAPE_PKEY) = {
  43. ASN1_EMBED(NETSCAPE_PKEY, version, INT32),
  44. ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
  45. ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
  46. } static_ASN1_SEQUENCE_END(NETSCAPE_PKEY)
  47. DECLARE_ASN1_FUNCTIONS(NETSCAPE_PKEY)
  48. DECLARE_ASN1_ENCODE_FUNCTIONS_name(NETSCAPE_PKEY, NETSCAPE_PKEY)
  49. IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_PKEY)