rfc2437.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. # PKCS#1 syntax
  8. #
  9. # ASN.1 source from:
  10. # ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2.asn
  11. #
  12. # Sample captures could be obtained with "openssl genrsa" command
  13. #
  14. from pyasn1.type import namedtype
  15. from pyasn1.type import tag
  16. from pyasn1.type import univ
  17. from pyasn1_modules.rfc2459 import AlgorithmIdentifier
  18. pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')
  19. rsaEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
  20. md2WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.2')
  21. md4WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.3')
  22. md5WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.4')
  23. sha1WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.5')
  24. rsaOAEPEncryptionSET = univ.ObjectIdentifier('1.2.840.113549.1.1.6')
  25. id_RSAES_OAEP = univ.ObjectIdentifier('1.2.840.113549.1.1.7')
  26. id_mgf1 = univ.ObjectIdentifier('1.2.840.113549.1.1.8')
  27. id_pSpecified = univ.ObjectIdentifier('1.2.840.113549.1.1.9')
  28. id_sha1 = univ.ObjectIdentifier('1.3.14.3.2.26')
  29. MAX = float('inf')
  30. class Version(univ.Integer):
  31. pass
  32. class RSAPrivateKey(univ.Sequence):
  33. componentType = namedtype.NamedTypes(
  34. namedtype.NamedType('version', Version()),
  35. namedtype.NamedType('modulus', univ.Integer()),
  36. namedtype.NamedType('publicExponent', univ.Integer()),
  37. namedtype.NamedType('privateExponent', univ.Integer()),
  38. namedtype.NamedType('prime1', univ.Integer()),
  39. namedtype.NamedType('prime2', univ.Integer()),
  40. namedtype.NamedType('exponent1', univ.Integer()),
  41. namedtype.NamedType('exponent2', univ.Integer()),
  42. namedtype.NamedType('coefficient', univ.Integer())
  43. )
  44. class RSAPublicKey(univ.Sequence):
  45. componentType = namedtype.NamedTypes(
  46. namedtype.NamedType('modulus', univ.Integer()),
  47. namedtype.NamedType('publicExponent', univ.Integer())
  48. )
  49. # XXX defaults not set
  50. class RSAES_OAEP_params(univ.Sequence):
  51. componentType = namedtype.NamedTypes(
  52. namedtype.NamedType('hashFunc', AlgorithmIdentifier().subtype(
  53. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  54. namedtype.NamedType('maskGenFunc', AlgorithmIdentifier().subtype(
  55. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  56. namedtype.NamedType('pSourceFunc', AlgorithmIdentifier().subtype(
  57. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  58. )