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.

rfc5084.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # This file is being contributed to pyasn1-modules software.
  2. #
  3. # Created by Russ Housley with assistance from the asn1ate tool, with manual
  4. # changes to AES_CCM_ICVlen.subtypeSpec and added comments
  5. #
  6. # Copyright (c) 2018-2019, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # AES-CCM and AES-GCM Algorithms fo use with the Authenticated-Enveloped-Data
  10. # protecting content type for the Cryptographic Message Syntax (CMS)
  11. #
  12. # ASN.1 source from:
  13. # https://www.rfc-editor.org/rfc/rfc5084.txt
  14. from pyasn1.type import constraint
  15. from pyasn1.type import namedtype
  16. from pyasn1.type import univ
  17. from pyasn1_modules import rfc5280
  18. def _OID(*components):
  19. output = []
  20. for x in tuple(components):
  21. if isinstance(x, univ.ObjectIdentifier):
  22. output.extend(list(x))
  23. else:
  24. output.append(int(x))
  25. return univ.ObjectIdentifier(output)
  26. class AES_CCM_ICVlen(univ.Integer):
  27. pass
  28. class AES_GCM_ICVlen(univ.Integer):
  29. pass
  30. AES_CCM_ICVlen.subtypeSpec = constraint.SingleValueConstraint(4, 6, 8, 10, 12, 14, 16)
  31. AES_GCM_ICVlen.subtypeSpec = constraint.ValueRangeConstraint(12, 16)
  32. class CCMParameters(univ.Sequence):
  33. pass
  34. CCMParameters.componentType = namedtype.NamedTypes(
  35. namedtype.NamedType('aes-nonce', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(7, 13))),
  36. # The aes-nonce parameter contains 15-L octets, where L is the size of the length field. L=8 is RECOMMENDED.
  37. # Within the scope of any content-authenticated-encryption key, the nonce value MUST be unique.
  38. namedtype.DefaultedNamedType('aes-ICVlen', AES_CCM_ICVlen().subtype(value=12))
  39. )
  40. class GCMParameters(univ.Sequence):
  41. pass
  42. GCMParameters.componentType = namedtype.NamedTypes(
  43. namedtype.NamedType('aes-nonce', univ.OctetString()),
  44. # The aes-nonce may have any number of bits between 8 and 2^64, but it MUST be a multiple of 8 bits.
  45. # Within the scope of any content-authenticated-encryption key, the nonce value MUST be unique.
  46. # A nonce value of 12 octets can be processed more efficiently, so that length is RECOMMENDED.
  47. namedtype.DefaultedNamedType('aes-ICVlen', AES_GCM_ICVlen().subtype(value=12))
  48. )
  49. aes = _OID(2, 16, 840, 1, 101, 3, 4, 1)
  50. id_aes128_CCM = _OID(aes, 7)
  51. id_aes128_GCM = _OID(aes, 6)
  52. id_aes192_CCM = _OID(aes, 27)
  53. id_aes192_GCM = _OID(aes, 26)
  54. id_aes256_CCM = _OID(aes, 47)
  55. id_aes256_GCM = _OID(aes, 46)
  56. # Map of Algorithm Identifier OIDs to Parameters is added to the
  57. # ones in rfc5280.py
  58. _algorithmIdentifierMapUpdate = {
  59. id_aes128_CCM: CCMParameters(),
  60. id_aes128_GCM: GCMParameters(),
  61. id_aes192_CCM: CCMParameters(),
  62. id_aes192_GCM: GCMParameters(),
  63. id_aes256_CCM: CCMParameters(),
  64. id_aes256_GCM: GCMParameters(),
  65. }
  66. rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)