aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pyasn1-modules/py3/pyasn1_modules/rfc4490.py
blob: b8fe32134e19f38dc385ab67082697235662868c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# This file is part of pyasn1-modules software.
#
# Created by Russ Housley with assistance from asn1ate v.0.6.0.
#
# Copyright (c) 2019, Vigil Security, LLC
# License: http://snmplabs.com/pyasn1/license.html
#
# Using the GOST 28147-89, GOST R 34.11-94, GOST R 34.10-94, and
#   GOST R 34.10-2001 Algorithms with the CMS
#
# ASN.1 source from:
# https://www.rfc-editor.org/rfc/rfc4490.txt
#


from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful

from pyasn1_modules import rfc4357
from pyasn1_modules import rfc5280


# Imports from RFC 4357

id_CryptoPro_algorithms = rfc4357.id_CryptoPro_algorithms

id_GostR3410_94 = rfc4357.id_GostR3410_94

id_GostR3410_2001 = rfc4357.id_GostR3410_2001

Gost28147_89_ParamSet = rfc4357.Gost28147_89_ParamSet

Gost28147_89_EncryptedKey = rfc4357.Gost28147_89_EncryptedKey

GostR3410_94_PublicKeyParameters = rfc4357.GostR3410_94_PublicKeyParameters

GostR3410_2001_PublicKeyParameters = rfc4357.GostR3410_2001_PublicKeyParameters


# Imports from RFC 5280

SubjectPublicKeyInfo = rfc5280.SubjectPublicKeyInfo


# CMS/PKCS#7 key agreement algorithms & parameters

class Gost28147_89_KeyWrapParameters(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet()),
        namedtype.OptionalNamedType('ukm', univ.OctetString().subtype(
            subtypeSpec=constraint.ValueSizeConstraint(8, 8)))
    )


id_Gost28147_89_CryptoPro_KeyWrap = id_CryptoPro_algorithms + (13, 1, )


id_Gost28147_89_None_KeyWrap = id_CryptoPro_algorithms + (13, 0, )


id_GostR3410_2001_CryptoPro_ESDH = id_CryptoPro_algorithms + (96, )


id_GostR3410_94_CryptoPro_ESDH = id_CryptoPro_algorithms + (97, )


# CMS/PKCS#7 key transport algorithms & parameters

id_GostR3410_2001_KeyTransportSMIMECapability = id_GostR3410_2001


id_GostR3410_94_KeyTransportSMIMECapability = id_GostR3410_94


class GostR3410_TransportParameters(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet()),
        namedtype.OptionalNamedType('ephemeralPublicKey', 
            SubjectPublicKeyInfo().subtype(implicitTag=tag.Tag(
                tag.tagClassContext, tag.tagFormatSimple, 0))),
        namedtype.NamedType('ukm', univ.OctetString().subtype(
            subtypeSpec=constraint.ValueSizeConstraint(8, 8)))
    )

class GostR3410_KeyTransport(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('sessionEncryptedKey', Gost28147_89_EncryptedKey()),
        namedtype.OptionalNamedType('transportParameters',
            GostR3410_TransportParameters().subtype(implicitTag=tag.Tag(
                tag.tagClassContext, tag.tagFormatConstructed, 0)))
    )


# GOST R 34.10-94 signature algorithm & parameters

class GostR3410_94_Signature(univ.OctetString):
    subtypeSpec = constraint.ValueSizeConstraint(64, 64)


# GOST R 34.10-2001 signature algorithms and parameters

class GostR3410_2001_Signature(univ.OctetString):
    subtypeSpec = constraint.ValueSizeConstraint(64, 64)


# Update the Algorithm Identifier map in rfc5280.py

_algorithmIdentifierMapUpdate = {
    id_Gost28147_89_CryptoPro_KeyWrap: Gost28147_89_KeyWrapParameters(),
    id_Gost28147_89_None_KeyWrap: Gost28147_89_KeyWrapParameters(),
}

rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)