A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.5 KiB

  1. /*
  2. * Copyright 2000-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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/bn.h>
  12. #include <openssl/x509.h>
  13. #include <openssl/asn1t.h>
  14. #include "rsa_locl.h"
  15. /* Override the default free and new methods */
  16. static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
  17. void *exarg)
  18. {
  19. if (operation == ASN1_OP_NEW_PRE) {
  20. *pval = (ASN1_VALUE *)RSA_new();
  21. if (*pval != NULL)
  22. return 2;
  23. return 0;
  24. } else if (operation == ASN1_OP_FREE_PRE) {
  25. RSA_free((RSA *)*pval);
  26. *pval = NULL;
  27. return 2;
  28. }
  29. return 1;
  30. }
  31. ASN1_SEQUENCE_cb(RSAPrivateKey, rsa_cb) = {
  32. ASN1_SIMPLE(RSA, version, LONG),
  33. ASN1_SIMPLE(RSA, n, BIGNUM),
  34. ASN1_SIMPLE(RSA, e, BIGNUM),
  35. ASN1_SIMPLE(RSA, d, CBIGNUM),
  36. ASN1_SIMPLE(RSA, p, CBIGNUM),
  37. ASN1_SIMPLE(RSA, q, CBIGNUM),
  38. ASN1_SIMPLE(RSA, dmp1, CBIGNUM),
  39. ASN1_SIMPLE(RSA, dmq1, CBIGNUM),
  40. ASN1_SIMPLE(RSA, iqmp, CBIGNUM)
  41. } ASN1_SEQUENCE_END_cb(RSA, RSAPrivateKey)
  42. ASN1_SEQUENCE_cb(RSAPublicKey, rsa_cb) = {
  43. ASN1_SIMPLE(RSA, n, BIGNUM),
  44. ASN1_SIMPLE(RSA, e, BIGNUM),
  45. } ASN1_SEQUENCE_END_cb(RSA, RSAPublicKey)
  46. ASN1_SEQUENCE(RSA_PSS_PARAMS) = {
  47. ASN1_EXP_OPT(RSA_PSS_PARAMS, hashAlgorithm, X509_ALGOR,0),
  48. ASN1_EXP_OPT(RSA_PSS_PARAMS, maskGenAlgorithm, X509_ALGOR,1),
  49. ASN1_EXP_OPT(RSA_PSS_PARAMS, saltLength, ASN1_INTEGER,2),
  50. ASN1_EXP_OPT(RSA_PSS_PARAMS, trailerField, ASN1_INTEGER,3)
  51. } ASN1_SEQUENCE_END(RSA_PSS_PARAMS)
  52. IMPLEMENT_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  53. ASN1_SEQUENCE(RSA_OAEP_PARAMS) = {
  54. ASN1_EXP_OPT(RSA_OAEP_PARAMS, hashFunc, X509_ALGOR, 0),
  55. ASN1_EXP_OPT(RSA_OAEP_PARAMS, maskGenFunc, X509_ALGOR, 1),
  56. ASN1_EXP_OPT(RSA_OAEP_PARAMS, pSourceFunc, X509_ALGOR, 2),
  57. } ASN1_SEQUENCE_END(RSA_OAEP_PARAMS)
  58. IMPLEMENT_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
  59. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPrivateKey, RSAPrivateKey)
  60. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPublicKey, RSAPublicKey)
  61. RSA *RSAPublicKey_dup(RSA *rsa)
  62. {
  63. return ASN1_item_dup(ASN1_ITEM_rptr(RSAPublicKey), rsa);
  64. }
  65. RSA *RSAPrivateKey_dup(RSA *rsa)
  66. {
  67. return ASN1_item_dup(ASN1_ITEM_rptr(RSAPrivateKey), rsa);
  68. }