rfc2437.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # PKCS#1 syntax
  3. #
  4. # ASN.1 source from:
  5. # ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2.asn
  6. #
  7. # Sample captures could be obtained with "openssl genrsa" command
  8. #
  9. from pyasn1.type import tag, namedtype, namedval, univ, constraint
  10. from pyasn1_modules.rfc2459 import AlgorithmIdentifier
  11. pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')
  12. rsaEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
  13. md2WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.2')
  14. md4WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.3')
  15. md5WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.4')
  16. sha1WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.5')
  17. rsaOAEPEncryptionSET = univ.ObjectIdentifier('1.2.840.113549.1.1.6')
  18. id_RSAES_OAEP = univ.ObjectIdentifier('1.2.840.113549.1.1.7')
  19. id_mgf1 = univ.ObjectIdentifier('1.2.840.113549.1.1.8')
  20. id_pSpecified = univ.ObjectIdentifier('1.2.840.113549.1.1.9')
  21. id_sha1 = univ.ObjectIdentifier('1.3.14.3.2.26')
  22. MAX = 16
  23. class Version(univ.Integer): pass
  24. class RSAPrivateKey(univ.Sequence):
  25. componentType = namedtype.NamedTypes(
  26. namedtype.NamedType('version', Version()),
  27. namedtype.NamedType('modulus', univ.Integer()),
  28. namedtype.NamedType('publicExponent', univ.Integer()),
  29. namedtype.NamedType('privateExponent', univ.Integer()),
  30. namedtype.NamedType('prime1', univ.Integer()),
  31. namedtype.NamedType('prime2', univ.Integer()),
  32. namedtype.NamedType('exponent1', univ.Integer()),
  33. namedtype.NamedType('exponent2', univ.Integer()),
  34. namedtype.NamedType('coefficient', univ.Integer())
  35. )
  36. class RSAPublicKey(univ.Sequence):
  37. componentType = namedtype.NamedTypes(
  38. namedtype.NamedType('modulus', univ.Integer()),
  39. namedtype.NamedType('publicExponent', univ.Integer())
  40. )
  41. # XXX defaults not set
  42. class RSAES_OAEP_params(univ.Sequence):
  43. componentType = namedtype.NamedTypes(
  44. namedtype.NamedType('hashFunc', AlgorithmIdentifier().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  45. namedtype.NamedType('maskGenFunc', AlgorithmIdentifier().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  46. namedtype.NamedType('pSourceFunc', AlgorithmIdentifier().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  47. )