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#
14from pyasn1.type import namedtype
15from pyasn1.type import tag
16from pyasn1.type import univ
17
18from pyasn1_modules.rfc2459 import AlgorithmIdentifier
19
20pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')
21rsaEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
22md2WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.2')
23md4WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.3')
24md5WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.4')
25sha1WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.5')
26rsaOAEPEncryptionSET = univ.ObjectIdentifier('1.2.840.113549.1.1.6')
27id_RSAES_OAEP = univ.ObjectIdentifier('1.2.840.113549.1.1.7')
28id_mgf1 = univ.ObjectIdentifier('1.2.840.113549.1.1.8')
29id_pSpecified = univ.ObjectIdentifier('1.2.840.113549.1.1.9')
30id_sha1 = univ.ObjectIdentifier('1.3.14.3.2.26')
31
32MAX = float('inf')
33
34
35class Version(univ.Integer):
36    pass
37
38
39class 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
53class 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
61class 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