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