Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rfc8017.py154 linesDownload Raw Back to pyasn1_modules
1#2# This file is part of pyasn1-modules software.3#4# Created by Russ Housley.5#6# Copyright (c) 2019, Vigil Security, LLC7# License: http://snmplabs.com/pyasn1/license.html8#9# PKCS #1: RSA Cryptography Specifications Version 2.210#11# ASN.1 source from:12# https://www.rfc-editor.org/rfc/rfc8017.txt13#14 15from pyasn1.type import constraint16from pyasn1.type import namedtype17from pyasn1.type import namedval18from pyasn1.type import univ19 20from pyasn1_modules import rfc243721from pyasn1_modules import rfc344722from pyasn1_modules import rfc405523from pyasn1_modules import rfc528024 25MAX = float('inf')26 27 28# Import Algorithm Identifier from RFC 528029 30AlgorithmIdentifier = rfc5280.AlgorithmIdentifier31 32class DigestAlgorithm(AlgorithmIdentifier):33    pass34 35class HashAlgorithm(AlgorithmIdentifier):36    pass37 38class MaskGenAlgorithm(AlgorithmIdentifier):39    pass40 41class PSourceAlgorithm(AlgorithmIdentifier):42    pass43 44 45# Object identifiers from NIST SHA246 47hashAlgs = univ.ObjectIdentifier('2.16.840.1.101.3.4.2')48id_sha256 = rfc4055.id_sha25649id_sha384 = rfc4055.id_sha38450id_sha512 = rfc4055.id_sha51251id_sha224 = rfc4055.id_sha22452id_sha512_224 = hashAlgs + (5, )53id_sha512_256 = hashAlgs + (6, )54 55 56# Basic object identifiers57 58pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')59rsaEncryption = rfc2437.rsaEncryption60id_RSAES_OAEP = rfc2437.id_RSAES_OAEP61id_pSpecified = rfc2437.id_pSpecified62id_RSASSA_PSS = rfc4055.id_RSASSA_PSS63md2WithRSAEncryption = rfc2437.md2WithRSAEncryption64md5WithRSAEncryption = rfc2437.md5WithRSAEncryption65sha1WithRSAEncryption = rfc2437.sha1WithRSAEncryption66sha224WithRSAEncryption = rfc4055.sha224WithRSAEncryption67sha256WithRSAEncryption = rfc4055.sha256WithRSAEncryption68sha384WithRSAEncryption = rfc4055.sha384WithRSAEncryption69sha512WithRSAEncryption = rfc4055.sha512WithRSAEncryption70sha512_224WithRSAEncryption = pkcs_1 + (15, )71sha512_256WithRSAEncryption = pkcs_1 + (16, )72id_sha1 = rfc2437.id_sha173id_md2 = univ.ObjectIdentifier('1.2.840.113549.2.2')74id_md5 = univ.ObjectIdentifier('1.2.840.113549.2.5')75id_mgf1 = rfc2437.id_mgf176 77 78# Default parameter values79 80sha1 = rfc4055.sha1Identifier81SHA1Parameters = univ.Null("")82 83mgf1SHA1 = rfc4055.mgf1SHA1Identifier84 85class EncodingParameters(univ.OctetString):86    subtypeSpec = constraint.ValueSizeConstraint(0, MAX)87 88pSpecifiedEmpty = rfc4055.pSpecifiedEmptyIdentifier89 90emptyString = EncodingParameters(value='')91 92 93# Main structures94 95class Version(univ.Integer):96    namedValues = namedval.NamedValues(97        ('two-prime', 0),98        ('multi', 1)99    )100 101class TrailerField(univ.Integer):102    namedValues = namedval.NamedValues(103       ('trailerFieldBC', 1)104    )105 106RSAPublicKey = rfc2437.RSAPublicKey107 108OtherPrimeInfo = rfc3447.OtherPrimeInfo109OtherPrimeInfos = rfc3447.OtherPrimeInfos110RSAPrivateKey = rfc3447.RSAPrivateKey111 112RSAES_OAEP_params = rfc4055.RSAES_OAEP_params113rSAES_OAEP_Default_Identifier = rfc4055.rSAES_OAEP_Default_Identifier114 115RSASSA_PSS_params = rfc4055.RSASSA_PSS_params116rSASSA_PSS_Default_Identifier = rfc4055.rSASSA_PSS_Default_Identifier117 118 119# Syntax for the EMSA-PKCS1-v1_5 hash identifier120 121class DigestInfo(univ.Sequence):122    componentType = namedtype.NamedTypes(123        namedtype.NamedType('digestAlgorithm', DigestAlgorithm()),124        namedtype.NamedType('digest', univ.OctetString())125    )126 127 128# Update the Algorithm Identifier map129 130_algorithmIdentifierMapUpdate = {131    id_sha1: univ.Null(),132    id_sha224: univ.Null(),133    id_sha256: univ.Null(),134    id_sha384: univ.Null(),135    id_sha512: univ.Null(),136    id_sha512_224: univ.Null(),137    id_sha512_256: univ.Null(),138    id_mgf1: AlgorithmIdentifier(),139    id_pSpecified: univ.OctetString(),140    id_RSAES_OAEP: RSAES_OAEP_params(),141    id_RSASSA_PSS: RSASSA_PSS_params(),142    md2WithRSAEncryption: univ.Null(),143    md5WithRSAEncryption: univ.Null(),144    sha1WithRSAEncryption: univ.Null(),145    sha224WithRSAEncryption: univ.Null(),146    sha256WithRSAEncryption: univ.Null(),147    sha384WithRSAEncryption: univ.Null(),148    sha512WithRSAEncryption: univ.Null(),149    sha512_224WithRSAEncryption: univ.Null(),150    sha512_256WithRSAEncryption: univ.Null(),151}152 153rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)154 
codekingpro/portable-devtools · Team Ai