rfc8702.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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) 2020, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # SHAKE One-way Hash Functions for CMS
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc8702.txt
  13. #
  14. from pyasn1.type import namedtype
  15. from pyasn1.type import tag
  16. from pyasn1.type import univ
  17. from pyasn1_modules import rfc5280
  18. from pyasn1_modules import rfc8692
  19. # Imports fprm RFC 5280
  20. AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
  21. # Imports from RFC 8692
  22. id_shake128 = rfc8692.id_shake128
  23. mda_shake128 = rfc8692.mda_shake128
  24. id_shake256 = rfc8692.id_shake256
  25. mda_shake256 = rfc8692.mda_shake256
  26. id_RSASSA_PSS_SHAKE128 = rfc8692.id_RSASSA_PSS_SHAKE128
  27. sa_rSASSA_PSS_SHAKE128 = rfc8692.sa_rSASSA_PSS_SHAKE128
  28. pk_rsaSSA_PSS_SHAKE128 = rfc8692.pk_rsaSSA_PSS_SHAKE128
  29. id_RSASSA_PSS_SHAKE256 = rfc8692.id_RSASSA_PSS_SHAKE256
  30. sa_rSASSA_PSS_SHAKE256 = rfc8692.sa_rSASSA_PSS_SHAKE256
  31. pk_rsaSSA_PSS_SHAKE256 = rfc8692.pk_rsaSSA_PSS_SHAKE256
  32. id_ecdsa_with_shake128 = rfc8692.id_ecdsa_with_shake128
  33. sa_ecdsa_with_shake128 = rfc8692.sa_ecdsa_with_shake128
  34. id_ecdsa_with_shake256 = rfc8692.id_ecdsa_with_shake256
  35. sa_ecdsa_with_shake256 = rfc8692.sa_ecdsa_with_shake256
  36. pk_ec = rfc8692.pk_ec
  37. # KMAC with SHAKE128
  38. id_KMACWithSHAKE128 = univ.ObjectIdentifier('2.16.840.1.101.3.4.2.19')
  39. class KMACwithSHAKE128_params(univ.Sequence):
  40. componentType = namedtype.NamedTypes(
  41. namedtype.DefaultedNamedType('kMACOutputLength',
  42. univ.Integer().subtype(value=256)),
  43. namedtype.DefaultedNamedType('customizationString',
  44. univ.OctetString().subtype(value=''))
  45. )
  46. maca_KMACwithSHAKE128 = AlgorithmIdentifier()
  47. maca_KMACwithSHAKE128['algorithm'] = id_KMACWithSHAKE128
  48. maca_KMACwithSHAKE128['parameters'] = KMACwithSHAKE128_params()
  49. # KMAC with SHAKE256
  50. id_KMACWithSHAKE256 = univ.ObjectIdentifier('2.16.840.1.101.3.4.2.20')
  51. class KMACwithSHAKE256_params(univ.Sequence):
  52. componentType = namedtype.NamedTypes(
  53. namedtype.DefaultedNamedType('kMACOutputLength',
  54. univ.Integer().subtype(value=512)),
  55. namedtype.DefaultedNamedType('customizationString',
  56. univ.OctetString().subtype(value=''))
  57. )
  58. maca_KMACwithSHAKE256 = AlgorithmIdentifier()
  59. maca_KMACwithSHAKE256['algorithm'] = id_KMACWithSHAKE256
  60. maca_KMACwithSHAKE256['parameters'] = KMACwithSHAKE256_params()
  61. # Update the Algorithm Identifier map in rfc5280.py
  62. _algorithmIdentifierMapUpdate = {
  63. id_KMACWithSHAKE128: KMACwithSHAKE128_params(),
  64. id_KMACWithSHAKE256: KMACwithSHAKE256_params(),
  65. }
  66. rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)