rfc5753.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. # Elliptic Curve Cryptography (ECC) Algorithms in the CMS
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc5753.txt
  13. #
  14. from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
  15. from pyasn1_modules import rfc5280
  16. from pyasn1_modules import rfc5480
  17. from pyasn1_modules import rfc5652
  18. from pyasn1_modules import rfc5751
  19. from pyasn1_modules import rfc8018
  20. # Imports from RFC 5280
  21. AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
  22. # Imports from RFC 5652
  23. OriginatorPublicKey = rfc5652.OriginatorPublicKey
  24. UserKeyingMaterial = rfc5652.UserKeyingMaterial
  25. # Imports from RFC 5480
  26. ECDSA_Sig_Value = rfc5480.ECDSA_Sig_Value
  27. ECParameters = rfc5480.ECParameters
  28. ECPoint = rfc5480.ECPoint
  29. id_ecPublicKey = rfc5480.id_ecPublicKey
  30. # Imports from RFC 8018
  31. id_hmacWithSHA224 = rfc8018.id_hmacWithSHA224
  32. id_hmacWithSHA256 = rfc8018.id_hmacWithSHA256
  33. id_hmacWithSHA384 = rfc8018.id_hmacWithSHA384
  34. id_hmacWithSHA512 = rfc8018.id_hmacWithSHA512
  35. # Object Identifier arcs
  36. x9_63_scheme = univ.ObjectIdentifier('1.3.133.16.840.63.0')
  37. secg_scheme = univ.ObjectIdentifier('1.3.132.1')
  38. # Object Identifiers for the algorithms
  39. dhSinglePass_cofactorDH_sha1kdf_scheme = x9_63_scheme + (3, )
  40. dhSinglePass_cofactorDH_sha224kdf_scheme = secg_scheme + (14, 0, )
  41. dhSinglePass_cofactorDH_sha256kdf_scheme = secg_scheme + (14, 1, )
  42. dhSinglePass_cofactorDH_sha384kdf_scheme = secg_scheme + (14, 2, )
  43. dhSinglePass_cofactorDH_sha512kdf_scheme = secg_scheme + (14, 3, )
  44. dhSinglePass_stdDH_sha1kdf_scheme = x9_63_scheme + (2, )
  45. dhSinglePass_stdDH_sha224kdf_scheme = secg_scheme + (11, 0, )
  46. dhSinglePass_stdDH_sha256kdf_scheme = secg_scheme + (11, 1, )
  47. dhSinglePass_stdDH_sha384kdf_scheme = secg_scheme + (11, 2, )
  48. dhSinglePass_stdDH_sha512kdf_scheme = secg_scheme + (11, 3, )
  49. mqvSinglePass_sha1kdf_scheme = x9_63_scheme + (16, )
  50. mqvSinglePass_sha224kdf_scheme = secg_scheme + (15, 0, )
  51. mqvSinglePass_sha256kdf_scheme = secg_scheme + (15, 1, )
  52. mqvSinglePass_sha384kdf_scheme = secg_scheme + (15, 2, )
  53. mqvSinglePass_sha512kdf_scheme = secg_scheme + (15, 3, )
  54. # Structures for parameters and key derivation
  55. class IV(univ.OctetString):
  56. # Exactly 8 octets
  57. pass
  58. class CBCParameter(IV):
  59. pass
  60. class KeyWrapAlgorithm(AlgorithmIdentifier):
  61. pass
  62. class ECC_CMS_SharedInfo(univ.Sequence):
  63. componentType = namedtype.NamedTypes(
  64. namedtype.NamedType('keyInfo', KeyWrapAlgorithm()),
  65. namedtype.OptionalNamedType('entityUInfo',
  66. univ.OctetString().subtype(explicitTag=tag.Tag(
  67. tag.tagClassContext, tag.tagFormatSimple, 0))),
  68. namedtype.NamedType('suppPubInfo',
  69. univ.OctetString().subtype(explicitTag=tag.Tag(
  70. tag.tagClassContext, tag.tagFormatSimple, 2)))
  71. )
  72. class MQVuserKeyingMaterial(univ.Sequence):
  73. componentType = namedtype.NamedTypes(
  74. namedtype.NamedType('ephemeralPublicKey', OriginatorPublicKey()),
  75. namedtype.OptionalNamedType('addedukm',
  76. UserKeyingMaterial().subtype(explicitTag=tag.Tag(
  77. tag.tagClassContext, tag.tagFormatSimple, 0)))
  78. )
  79. # Update the Algorithm Identifier map in rfc5280.py and
  80. # Update the SMIMECapabilities Attribute Map in rfc5751.py
  81. _algorithmIdentifierMapUpdate = {
  82. dhSinglePass_stdDH_sha1kdf_scheme: KeyWrapAlgorithm(),
  83. dhSinglePass_stdDH_sha224kdf_scheme: KeyWrapAlgorithm(),
  84. dhSinglePass_stdDH_sha256kdf_scheme: KeyWrapAlgorithm(),
  85. dhSinglePass_stdDH_sha384kdf_scheme: KeyWrapAlgorithm(),
  86. dhSinglePass_stdDH_sha512kdf_scheme: KeyWrapAlgorithm(),
  87. dhSinglePass_cofactorDH_sha1kdf_scheme: KeyWrapAlgorithm(),
  88. dhSinglePass_cofactorDH_sha224kdf_scheme: KeyWrapAlgorithm(),
  89. dhSinglePass_cofactorDH_sha256kdf_scheme: KeyWrapAlgorithm(),
  90. dhSinglePass_cofactorDH_sha384kdf_scheme: KeyWrapAlgorithm(),
  91. dhSinglePass_cofactorDH_sha512kdf_scheme: KeyWrapAlgorithm(),
  92. mqvSinglePass_sha1kdf_scheme: KeyWrapAlgorithm(),
  93. mqvSinglePass_sha224kdf_scheme: KeyWrapAlgorithm(),
  94. mqvSinglePass_sha256kdf_scheme: KeyWrapAlgorithm(),
  95. mqvSinglePass_sha384kdf_scheme: KeyWrapAlgorithm(),
  96. mqvSinglePass_sha512kdf_scheme: KeyWrapAlgorithm(),
  97. }
  98. rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)
  99. rfc5751.smimeCapabilityMap.update(_algorithmIdentifierMapUpdate)