rfc2437.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
  5. # License: http://pyasn1.sf.net/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 tag, namedtype, univ
  15. from pyasn1_modules.rfc2459 import AlgorithmIdentifier
  16. pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')
  17. rsaEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
  18. md2WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.2')
  19. md4WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.3')
  20. md5WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.4')
  21. sha1WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.5')
  22. rsaOAEPEncryptionSET = univ.ObjectIdentifier('1.2.840.113549.1.1.6')
  23. id_RSAES_OAEP = univ.ObjectIdentifier('1.2.840.113549.1.1.7')
  24. id_mgf1 = univ.ObjectIdentifier('1.2.840.113549.1.1.8')
  25. id_pSpecified = univ.ObjectIdentifier('1.2.840.113549.1.1.9')
  26. id_sha1 = univ.ObjectIdentifier('1.3.14.3.2.26')
  27. MAX = 16
  28. class Version(univ.Integer):
  29. pass
  30. class RSAPrivateKey(univ.Sequence):
  31. componentType = namedtype.NamedTypes(
  32. namedtype.NamedType('version', Version()),
  33. namedtype.NamedType('modulus', univ.Integer()),
  34. namedtype.NamedType('publicExponent', univ.Integer()),
  35. namedtype.NamedType('privateExponent', univ.Integer()),
  36. namedtype.NamedType('prime1', univ.Integer()),
  37. namedtype.NamedType('prime2', univ.Integer()),
  38. namedtype.NamedType('exponent1', univ.Integer()),
  39. namedtype.NamedType('exponent2', univ.Integer()),
  40. namedtype.NamedType('coefficient', univ.Integer())
  41. )
  42. class RSAPublicKey(univ.Sequence):
  43. componentType = namedtype.NamedTypes(
  44. namedtype.NamedType('modulus', univ.Integer()),
  45. namedtype.NamedType('publicExponent', univ.Integer())
  46. )
  47. # XXX defaults not set
  48. class RSAES_OAEP_params(univ.Sequence):
  49. componentType = namedtype.NamedTypes(
  50. namedtype.NamedType('hashFunc', AlgorithmIdentifier().subtype(
  51. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  52. namedtype.NamedType('maskGenFunc', AlgorithmIdentifier().subtype(
  53. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  54. namedtype.NamedType('pSourceFunc', AlgorithmIdentifier().subtype(
  55. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  56. )