Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc4357.py 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley with assistance from asn1ate v.0.6.0.
  5. #
  6. # Copyright (c) 2019, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # Additional Cryptographic Algorithms for Use with GOST 28147-89,
  10. # GOST R 34.10-94, GOST R 34.10-2001, and GOST R 34.11-94 Algorithms
  11. #
  12. # ASN.1 source from:
  13. # https://www.rfc-editor.org/rfc/rfc4357.txt
  14. # https://www.rfc-editor.org/errata/eid5927
  15. # https://www.rfc-editor.org/errata/eid5928
  16. #
  17. from pyasn1.type import constraint
  18. from pyasn1.type import namedtype
  19. from pyasn1.type import namedval
  20. from pyasn1.type import tag
  21. from pyasn1.type import univ
  22. from pyasn1_modules import rfc5280
  23. # Import from RFC 5280
  24. AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
  25. # Object Identifiers
  26. id_CryptoPro = univ.ObjectIdentifier((1, 2, 643, 2, 2,))
  27. id_CryptoPro_modules = id_CryptoPro + (1, 1,)
  28. id_CryptoPro_extensions = id_CryptoPro + (34,)
  29. id_CryptoPro_policyIds = id_CryptoPro + (38,)
  30. id_CryptoPro_policyQt = id_CryptoPro + (39,)
  31. cryptographic_Gost_Useful_Definitions = id_CryptoPro_modules + (0, 1,)
  32. gostR3411_94_DigestSyntax = id_CryptoPro_modules + (1, 1,)
  33. gostR3410_94_PKISyntax = id_CryptoPro_modules + (2, 1,)
  34. gostR3410_94_SignatureSyntax = id_CryptoPro_modules + (3, 1,)
  35. gost28147_89_EncryptionSyntax = id_CryptoPro_modules + (4, 1,)
  36. gostR3410_EncryptionSyntax = id_CryptoPro_modules + (5, 2,)
  37. gost28147_89_ParamSetSyntax = id_CryptoPro_modules + (6, 1,)
  38. gostR3411_94_ParamSetSyntax = id_CryptoPro_modules + (7, 1,)
  39. gostR3410_94_ParamSetSyntax = id_CryptoPro_modules + (8, 1, 1)
  40. gostR3410_2001_PKISyntax = id_CryptoPro_modules + (9, 1,)
  41. gostR3410_2001_SignatureSyntax = id_CryptoPro_modules + (10, 1,)
  42. gostR3410_2001_ParamSetSyntax = id_CryptoPro_modules + (12, 1,)
  43. gost_CryptoPro_ExtendedKeyUsage = id_CryptoPro_modules + (13, 1,)
  44. gost_CryptoPro_PrivateKey = id_CryptoPro_modules + (14, 1,)
  45. gost_CryptoPro_PKIXCMP = id_CryptoPro_modules + (15, 1,)
  46. gost_CryptoPro_TLS = id_CryptoPro_modules + (16, 1,)
  47. gost_CryptoPro_Policy = id_CryptoPro_modules + (17, 1,)
  48. gost_CryptoPro_Constants = id_CryptoPro_modules + (18, 1,)
  49. id_CryptoPro_algorithms = id_CryptoPro
  50. id_GostR3411_94_with_GostR3410_2001 = id_CryptoPro_algorithms + (3,)
  51. id_GostR3411_94_with_GostR3410_94 = id_CryptoPro_algorithms + (4,)
  52. id_GostR3411_94 = id_CryptoPro_algorithms + (9,)
  53. id_Gost28147_89_None_KeyMeshing = id_CryptoPro_algorithms + (14, 0,)
  54. id_Gost28147_89_CryptoPro_KeyMeshing = id_CryptoPro_algorithms + (14, 1,)
  55. id_GostR3410_2001 = id_CryptoPro_algorithms + (19,)
  56. id_GostR3410_94 = id_CryptoPro_algorithms + (20,)
  57. id_Gost28147_89 = id_CryptoPro_algorithms + (21,)
  58. id_Gost28147_89_MAC = id_CryptoPro_algorithms + (22,)
  59. id_CryptoPro_hashes = id_CryptoPro_algorithms + (30,)
  60. id_CryptoPro_encrypts = id_CryptoPro_algorithms + (31,)
  61. id_CryptoPro_signs = id_CryptoPro_algorithms + (32,)
  62. id_CryptoPro_exchanges = id_CryptoPro_algorithms + (33,)
  63. id_CryptoPro_ecc_signs = id_CryptoPro_algorithms + (35,)
  64. id_CryptoPro_ecc_exchanges = id_CryptoPro_algorithms + (36,)
  65. id_CryptoPro_private_keys = id_CryptoPro_algorithms + (37,)
  66. id_CryptoPro_pkixcmp_infos = id_CryptoPro_algorithms + (41,)
  67. id_CryptoPro_audit_service_types = id_CryptoPro_algorithms + (42,)
  68. id_CryptoPro_audit_record_types = id_CryptoPro_algorithms + (43,)
  69. id_CryptoPro_attributes = id_CryptoPro_algorithms + (44,)
  70. id_CryptoPro_name_service_types = id_CryptoPro_algorithms + (45,)
  71. id_GostR3410_2001DH = id_CryptoPro_algorithms + (98,)
  72. id_GostR3410_94DH = id_CryptoPro_algorithms + (99,)
  73. id_Gost28147_89_TestParamSet = id_CryptoPro_encrypts + (0,)
  74. id_Gost28147_89_CryptoPro_A_ParamSet = id_CryptoPro_encrypts + (1,)
  75. id_Gost28147_89_CryptoPro_B_ParamSet = id_CryptoPro_encrypts + (2,)
  76. id_Gost28147_89_CryptoPro_C_ParamSet = id_CryptoPro_encrypts + (3,)
  77. id_Gost28147_89_CryptoPro_D_ParamSet = id_CryptoPro_encrypts + (4,)
  78. id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet = id_CryptoPro_encrypts + (5,)
  79. id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet = id_CryptoPro_encrypts + (6,)
  80. id_Gost28147_89_CryptoPro_RIC_1_ParamSet = id_CryptoPro_encrypts + (7,)
  81. id_GostR3410_2001_TestParamSet = id_CryptoPro_ecc_signs + (0,)
  82. id_GostR3410_2001_CryptoPro_A_ParamSet = id_CryptoPro_ecc_signs + (1,)
  83. id_GostR3410_2001_CryptoPro_B_ParamSet = id_CryptoPro_ecc_signs + (2,)
  84. id_GostR3410_2001_CryptoPro_C_ParamSet = id_CryptoPro_ecc_signs + (3,)
  85. id_GostR3410_2001_CryptoPro_XchA_ParamSet = id_CryptoPro_ecc_exchanges + (0,)
  86. id_GostR3410_2001_CryptoPro_XchB_ParamSet = id_CryptoPro_ecc_exchanges + (1,)
  87. id_GostR3410_94_TestParamSet = id_CryptoPro_signs + (0,)
  88. id_GostR3410_94_CryptoPro_A_ParamSet = id_CryptoPro_signs + (2,)
  89. id_GostR3410_94_CryptoPro_B_ParamSet = id_CryptoPro_signs + (3,)
  90. id_GostR3410_94_CryptoPro_C_ParamSet = id_CryptoPro_signs + (4,)
  91. id_GostR3410_94_CryptoPro_D_ParamSet = id_CryptoPro_signs + (5,)
  92. id_GostR3410_94_CryptoPro_XchA_ParamSet = id_CryptoPro_exchanges + (1,)
  93. id_GostR3410_94_CryptoPro_XchB_ParamSet = id_CryptoPro_exchanges + (2,)
  94. id_GostR3410_94_CryptoPro_XchC_ParamSet = id_CryptoPro_exchanges + (3,)
  95. id_GostR3410_94_a = id_GostR3410_94 + (1,)
  96. id_GostR3410_94_aBis = id_GostR3410_94 + (2,)
  97. id_GostR3410_94_b = id_GostR3410_94 + (3,)
  98. id_GostR3410_94_bBis = id_GostR3410_94 + (4,)
  99. id_GostR3411_94_TestParamSet = id_CryptoPro_hashes + (0,)
  100. id_GostR3411_94_CryptoProParamSet = id_CryptoPro_hashes + (1,)
  101. class Gost28147_89_ParamSet(univ.ObjectIdentifier):
  102. pass
  103. Gost28147_89_ParamSet.subtypeSpec = constraint.SingleValueConstraint(
  104. id_Gost28147_89_TestParamSet,
  105. id_Gost28147_89_CryptoPro_A_ParamSet,
  106. id_Gost28147_89_CryptoPro_B_ParamSet,
  107. id_Gost28147_89_CryptoPro_C_ParamSet,
  108. id_Gost28147_89_CryptoPro_D_ParamSet,
  109. id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet,
  110. id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet,
  111. id_Gost28147_89_CryptoPro_RIC_1_ParamSet
  112. )
  113. class Gost28147_89_BlobParameters(univ.Sequence):
  114. pass
  115. Gost28147_89_BlobParameters.componentType = namedtype.NamedTypes(
  116. namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet())
  117. )
  118. class Gost28147_89_MAC(univ.OctetString):
  119. pass
  120. Gost28147_89_MAC.subtypeSpec = constraint.ValueSizeConstraint(1, 4)
  121. class Gost28147_89_Key(univ.OctetString):
  122. pass
  123. Gost28147_89_Key.subtypeSpec = constraint.ValueSizeConstraint(32, 32)
  124. class Gost28147_89_EncryptedKey(univ.Sequence):
  125. pass
  126. Gost28147_89_EncryptedKey.componentType = namedtype.NamedTypes(
  127. namedtype.NamedType('encryptedKey', Gost28147_89_Key()),
  128. namedtype.OptionalNamedType('maskKey', Gost28147_89_Key().subtype(
  129. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  130. namedtype.NamedType('macKey', Gost28147_89_MAC())
  131. )
  132. class Gost28147_89_IV(univ.OctetString):
  133. pass
  134. Gost28147_89_IV.subtypeSpec = constraint.ValueSizeConstraint(8, 8)
  135. class Gost28147_89_UZ(univ.OctetString):
  136. pass
  137. Gost28147_89_UZ.subtypeSpec = constraint.ValueSizeConstraint(64, 64)
  138. class Gost28147_89_ParamSetParameters(univ.Sequence):
  139. pass
  140. Gost28147_89_ParamSetParameters.componentType = namedtype.NamedTypes(
  141. namedtype.NamedType('eUZ', Gost28147_89_UZ()),
  142. namedtype.NamedType('mode',
  143. univ.Integer(namedValues=namedval.NamedValues(
  144. ('gost28147-89-CNT', 0),
  145. ('gost28147-89-CFB', 1),
  146. ('cryptoPro-CBC', 2)
  147. ))),
  148. namedtype.NamedType('shiftBits',
  149. univ.Integer(namedValues=namedval.NamedValues(
  150. ('gost28147-89-block', 64)
  151. ))),
  152. namedtype.NamedType('keyMeshing', AlgorithmIdentifier())
  153. )
  154. class Gost28147_89_Parameters(univ.Sequence):
  155. pass
  156. Gost28147_89_Parameters.componentType = namedtype.NamedTypes(
  157. namedtype.NamedType('iv', Gost28147_89_IV()),
  158. namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet())
  159. )
  160. class GostR3410_2001_CertificateSignature(univ.BitString):
  161. pass
  162. GostR3410_2001_CertificateSignature.subtypeSpec=constraint.ValueSizeConstraint(256, 512)
  163. class GostR3410_2001_ParamSetParameters(univ.Sequence):
  164. pass
  165. GostR3410_2001_ParamSetParameters.componentType = namedtype.NamedTypes(
  166. namedtype.NamedType('a', univ.Integer()),
  167. namedtype.NamedType('b', univ.Integer()),
  168. namedtype.NamedType('p', univ.Integer()),
  169. namedtype.NamedType('q', univ.Integer()),
  170. namedtype.NamedType('x', univ.Integer()),
  171. namedtype.NamedType('y', univ.Integer())
  172. )
  173. class GostR3410_2001_PublicKey(univ.OctetString):
  174. pass
  175. GostR3410_2001_PublicKey.subtypeSpec = constraint.ValueSizeConstraint(64, 64)
  176. class GostR3410_2001_PublicKeyParameters(univ.Sequence):
  177. pass
  178. GostR3410_2001_PublicKeyParameters.componentType = namedtype.NamedTypes(
  179. namedtype.NamedType('publicKeyParamSet', univ.ObjectIdentifier().subtype(
  180. subtypeSpec=constraint.SingleValueConstraint(
  181. id_GostR3410_2001_TestParamSet,
  182. id_GostR3410_2001_CryptoPro_A_ParamSet,
  183. id_GostR3410_2001_CryptoPro_B_ParamSet,
  184. id_GostR3410_2001_CryptoPro_C_ParamSet,
  185. id_GostR3410_2001_CryptoPro_XchA_ParamSet,
  186. id_GostR3410_2001_CryptoPro_XchB_ParamSet
  187. ))),
  188. namedtype.NamedType('digestParamSet', univ.ObjectIdentifier().subtype(
  189. subtypeSpec=constraint.SingleValueConstraint(
  190. id_GostR3411_94_TestParamSet,
  191. id_GostR3411_94_CryptoProParamSet
  192. ))),
  193. namedtype.DefaultedNamedType('encryptionParamSet',
  194. Gost28147_89_ParamSet().subtype(value=id_Gost28147_89_CryptoPro_A_ParamSet
  195. ))
  196. )
  197. class GostR3410_94_CertificateSignature(univ.BitString):
  198. pass
  199. GostR3410_94_CertificateSignature.subtypeSpec = constraint.ValueSizeConstraint(256, 512)
  200. class GostR3410_94_ParamSetParameters_t(univ.Integer):
  201. pass
  202. GostR3410_94_ParamSetParameters_t.subtypeSpec = constraint.SingleValueConstraint(512, 1024)
  203. class GostR3410_94_ParamSetParameters(univ.Sequence):
  204. pass
  205. GostR3410_94_ParamSetParameters.componentType = namedtype.NamedTypes(
  206. namedtype.NamedType('t', GostR3410_94_ParamSetParameters_t()),
  207. namedtype.NamedType('p', univ.Integer()),
  208. namedtype.NamedType('q', univ.Integer()),
  209. namedtype.NamedType('a', univ.Integer()),
  210. namedtype.OptionalNamedType('validationAlgorithm', AlgorithmIdentifier())
  211. )
  212. class GostR3410_94_PublicKey(univ.OctetString):
  213. pass
  214. GostR3410_94_PublicKey.subtypeSpec = constraint.ConstraintsUnion(
  215. constraint.ValueSizeConstraint(64, 64),
  216. constraint.ValueSizeConstraint(128, 128)
  217. )
  218. class GostR3410_94_PublicKeyParameters(univ.Sequence):
  219. pass
  220. GostR3410_94_PublicKeyParameters.componentType = namedtype.NamedTypes(
  221. namedtype.NamedType('publicKeyParamSet', univ.ObjectIdentifier().subtype(
  222. subtypeSpec=constraint.SingleValueConstraint(
  223. id_GostR3410_94_TestParamSet,
  224. id_GostR3410_94_CryptoPro_A_ParamSet,
  225. id_GostR3410_94_CryptoPro_B_ParamSet,
  226. id_GostR3410_94_CryptoPro_C_ParamSet,
  227. id_GostR3410_94_CryptoPro_D_ParamSet,
  228. id_GostR3410_94_CryptoPro_XchA_ParamSet,
  229. id_GostR3410_94_CryptoPro_XchB_ParamSet,
  230. id_GostR3410_94_CryptoPro_XchC_ParamSet
  231. ))),
  232. namedtype.NamedType('digestParamSet', univ.ObjectIdentifier().subtype(
  233. subtypeSpec=constraint.SingleValueConstraint(
  234. id_GostR3411_94_TestParamSet,
  235. id_GostR3411_94_CryptoProParamSet
  236. ))),
  237. namedtype.DefaultedNamedType('encryptionParamSet',
  238. Gost28147_89_ParamSet().subtype(value=id_Gost28147_89_CryptoPro_A_ParamSet
  239. ))
  240. )
  241. class GostR3410_94_ValidationBisParameters_c(univ.Integer):
  242. pass
  243. GostR3410_94_ValidationBisParameters_c.subtypeSpec = constraint.ValueRangeConstraint(0, 4294967295)
  244. class GostR3410_94_ValidationBisParameters(univ.Sequence):
  245. pass
  246. GostR3410_94_ValidationBisParameters.componentType = namedtype.NamedTypes(
  247. namedtype.NamedType('x0', GostR3410_94_ValidationBisParameters_c()),
  248. namedtype.NamedType('c', GostR3410_94_ValidationBisParameters_c()),
  249. namedtype.OptionalNamedType('d', univ.Integer())
  250. )
  251. class GostR3410_94_ValidationParameters_c(univ.Integer):
  252. pass
  253. GostR3410_94_ValidationParameters_c.subtypeSpec = constraint.ValueRangeConstraint(0, 65535)
  254. class GostR3410_94_ValidationParameters(univ.Sequence):
  255. pass
  256. GostR3410_94_ValidationParameters.componentType = namedtype.NamedTypes(
  257. namedtype.NamedType('x0', GostR3410_94_ValidationParameters_c()),
  258. namedtype.NamedType('c', GostR3410_94_ValidationParameters_c()),
  259. namedtype.OptionalNamedType('d', univ.Integer())
  260. )
  261. class GostR3411_94_Digest(univ.OctetString):
  262. pass
  263. GostR3411_94_Digest.subtypeSpec = constraint.ValueSizeConstraint(32, 32)
  264. class GostR3411_94_DigestParameters(univ.ObjectIdentifier):
  265. pass
  266. GostR3411_94_DigestParameters.subtypeSpec = constraint.ConstraintsUnion(
  267. constraint.SingleValueConstraint(id_GostR3411_94_TestParamSet),
  268. constraint.SingleValueConstraint(id_GostR3411_94_CryptoProParamSet),
  269. )
  270. class GostR3411_94_ParamSetParameters(univ.Sequence):
  271. pass
  272. GostR3411_94_ParamSetParameters.componentType = namedtype.NamedTypes(
  273. namedtype.NamedType('hUZ', Gost28147_89_UZ()),
  274. namedtype.NamedType('h0', GostR3411_94_Digest())
  275. )
  276. # Update the Algorithm Identifier map in rfc5280.py
  277. _algorithmIdentifierMapUpdate = {
  278. id_Gost28147_89: Gost28147_89_Parameters(),
  279. id_Gost28147_89_TestParamSet: Gost28147_89_ParamSetParameters(),
  280. id_Gost28147_89_CryptoPro_A_ParamSet: Gost28147_89_ParamSetParameters(),
  281. id_Gost28147_89_CryptoPro_B_ParamSet: Gost28147_89_ParamSetParameters(),
  282. id_Gost28147_89_CryptoPro_C_ParamSet: Gost28147_89_ParamSetParameters(),
  283. id_Gost28147_89_CryptoPro_D_ParamSet: Gost28147_89_ParamSetParameters(),
  284. id_Gost28147_89_CryptoPro_KeyMeshing: univ.Null(""),
  285. id_Gost28147_89_None_KeyMeshing: univ.Null(""),
  286. id_GostR3410_94: GostR3410_94_PublicKeyParameters(),
  287. id_GostR3410_94_TestParamSet: GostR3410_94_ParamSetParameters(),
  288. id_GostR3410_94_CryptoPro_A_ParamSet: GostR3410_94_ParamSetParameters(),
  289. id_GostR3410_94_CryptoPro_B_ParamSet: GostR3410_94_ParamSetParameters(),
  290. id_GostR3410_94_CryptoPro_C_ParamSet: GostR3410_94_ParamSetParameters(),
  291. id_GostR3410_94_CryptoPro_D_ParamSet: GostR3410_94_ParamSetParameters(),
  292. id_GostR3410_94_CryptoPro_XchA_ParamSet: GostR3410_94_ParamSetParameters(),
  293. id_GostR3410_94_CryptoPro_XchB_ParamSet: GostR3410_94_ParamSetParameters(),
  294. id_GostR3410_94_CryptoPro_XchC_ParamSet: GostR3410_94_ParamSetParameters(),
  295. id_GostR3410_94_a: GostR3410_94_ValidationParameters(),
  296. id_GostR3410_94_aBis: GostR3410_94_ValidationBisParameters(),
  297. id_GostR3410_94_b: GostR3410_94_ValidationParameters(),
  298. id_GostR3410_94_bBis: GostR3410_94_ValidationBisParameters(),
  299. id_GostR3410_2001: univ.Null(""),
  300. id_GostR3411_94: univ.Null(""),
  301. id_GostR3411_94_TestParamSet: GostR3411_94_ParamSetParameters(),
  302. id_GostR3411_94_CryptoProParamSet: GostR3411_94_ParamSetParameters(),
  303. }
  304. rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)