1 # 2 # This file is part of pyasn1-modules. 3 # 4 # Copyright (c) 2017, Danielle Madeley <danielle (at] madeley.id.au> 5 # License: http://pyasn1.sf.net/license.html 6 # 7 # Derived from RFC 3279 8 # 9 from pyasn1.type import namedtype 10 from pyasn1.type import namedval 11 from pyasn1.type import univ 12 13 14 def _OID(*components): 15 output = [] 16 for x in tuple(components): 17 if isinstance(x, univ.ObjectIdentifier): 18 output.extend(list(x)) 19 else: 20 output.append(int(x)) 21 22 return univ.ObjectIdentifier(output) 23 24 25 md2 = _OID(1, 2, 840, 113549, 2, 2) 26 md5 = _OID(1, 2, 840, 113549, 2, 5) 27 id_sha1 = _OID(1, 3, 14, 3, 2, 26) 28 id_dsa = _OID(1, 2, 840, 10040, 4, 1) 29 30 31 class DSAPublicKey(univ.Integer): 32 pass 33 34 35 class Dss_Parms(univ.Sequence): 36 componentType = namedtype.NamedTypes( 37 namedtype.NamedType('p', univ.Integer()), 38 namedtype.NamedType('q', univ.Integer()), 39 namedtype.NamedType('g', univ.Integer()) 40 ) 41 42 43 id_dsa_with_sha1 = _OID(1, 2, 840, 10040, 4, 3) 44 45 46 class Dss_Sig_Value(univ.Sequence): 47 componentType = namedtype.NamedTypes( 48 namedtype.NamedType('r', univ.Integer()), 49 namedtype.NamedType('s', univ.Integer()) 50 ) 51 52 53 pkcs_1 = _OID(1, 2, 840, 113549, 1, 1) 54 rsaEncryption = _OID(pkcs_1, 1) 55 md2WithRSAEncryption = _OID(pkcs_1, 2) 56 md5WithRSAEncryption = _OID(pkcs_1, 4) 57 sha1WithRSAEncryption = _OID(pkcs_1, 5) 58 59 60 class RSAPublicKey(univ.Sequence): 61 componentType = namedtype.NamedTypes( 62 namedtype.NamedType('modulus', univ.Integer()), 63 namedtype.NamedType('publicExponent', univ.Integer()) 64 ) 65 66 67 dhpublicnumber = _OID(1, 2, 840, 10046, 2, 1) 68 69 70 class DHPublicKey(univ.Integer): 71 pass 72 73 74 class ValidationParms(univ.Sequence): 75 componentType = namedtype.NamedTypes( 76 namedtype.NamedType('seed', univ.BitString()), 77 namedtype.NamedType('pgenCounter', univ.Integer()) 78 ) 79 80 81 class DomainParameters(univ.Sequence): 82 componentType = namedtype.NamedTypes( 83 namedtype.NamedType('p', univ.Integer()), 84 namedtype.NamedType('g', univ.Integer()), 85 namedtype.NamedType('q', univ.Integer()), 86 namedtype.OptionalNamedType('j', univ.Integer()), 87 namedtype.OptionalNamedType('validationParms', ValidationParms()) 88 ) 89 90 91 id_keyExchangeAlgorithm = _OID(2, 16, 840, 1, 101, 2, 1, 1, 22) 92 93 94 class KEA_Parms_Id(univ.OctetString): 95 pass 96 97 98 ansi_X9_62 = _OID(1, 2, 840, 10045) 99 100 101 class FieldID(univ.Sequence): 102 componentType = namedtype.NamedTypes( 103 namedtype.NamedType('fieldType', univ.ObjectIdentifier()), 104 namedtype.NamedType('parameters', univ.Any()) 105 ) 106 107 108 id_ecSigType = _OID(ansi_X9_62, 4) 109 ecdsa_with_SHA1 = _OID(id_ecSigType, 1) 110 111 112 class ECDSA_Sig_Value(univ.Sequence): 113 componentType = namedtype.NamedTypes( 114 namedtype.NamedType('r', univ.Integer()), 115 namedtype.NamedType('s', univ.Integer()) 116 ) 117 118 119 id_fieldType = _OID(ansi_X9_62, 1) 120 prime_field = _OID(id_fieldType, 1) 121 122 123 class Prime_p(univ.Integer): 124 pass 125 126 127 characteristic_two_field = _OID(id_fieldType, 2) 128 129 130 class Characteristic_two(univ.Sequence): 131 componentType = namedtype.NamedTypes( 132 namedtype.NamedType('m', univ.Integer()), 133 namedtype.NamedType('basis', univ.ObjectIdentifier()), 134 namedtype.NamedType('parameters', univ.Any()) 135 ) 136 137 138 id_characteristic_two_basis = _OID(characteristic_two_field, 3) 139 gnBasis = _OID(id_characteristic_two_basis, 1) 140 tpBasis = _OID(id_characteristic_two_basis, 2) 141 142 143 class Trinomial(univ.Integer): 144 pass 145 146 147 ppBasis = _OID(id_characteristic_two_basis, 3) 148 149 150 class Pentanomial(univ.Sequence): 151 componentType = namedtype.NamedTypes( 152 namedtype.NamedType('k1', univ.Integer()), 153 namedtype.NamedType('k2', univ.Integer()), 154 namedtype.NamedType('k3', univ.Integer()) 155 ) 156 157 158 class FieldElement(univ.OctetString): 159 pass 160 161 162 class ECPoint(univ.OctetString): 163 pass 164 165 166 class Curve(univ.Sequence): 167 componentType = namedtype.NamedTypes( 168 namedtype.NamedType('a', FieldElement()), 169 namedtype.NamedType('b', FieldElement()), 170 namedtype.OptionalNamedType('seed', univ.BitString()) 171 ) 172 173 174 class ECPVer(univ.Integer): 175 namedValues = namedval.NamedValues( 176 ('ecpVer1', 1) 177 ) 178 179 180 class ECParameters(univ.Sequence): 181 componentType = namedtype.NamedTypes( 182 namedtype.NamedType('version', ECPVer()), 183 namedtype.NamedType('fieldID', FieldID()), 184 namedtype.NamedType('curve', Curve()), 185 namedtype.NamedType('base', ECPoint()), 186 namedtype.NamedType('order', univ.Integer()), 187 namedtype.OptionalNamedType('cofactor', univ.Integer()) 188 ) 189 190 191 class EcpkParameters(univ.Choice): 192 componentType = namedtype.NamedTypes( 193 namedtype.NamedType('ecParameters', ECParameters()), 194 namedtype.NamedType('namedCurve', univ.ObjectIdentifier()), 195 namedtype.NamedType('implicitlyCA', univ.Null()) 196 ) 197 198 199 id_publicKeyType = _OID(ansi_X9_62, 2) 200 id_ecPublicKey = _OID(id_publicKeyType, 1) 201 202 ellipticCurve = _OID(ansi_X9_62, 3) 203 204 c_TwoCurve = _OID(ellipticCurve, 0) 205 c2pnb163v1 = _OID(c_TwoCurve, 1) 206 c2pnb163v2 = _OID(c_TwoCurve, 2) 207 c2pnb163v3 = _OID(c_TwoCurve, 3) 208 c2pnb176w1 = _OID(c_TwoCurve, 4) 209 c2tnb191v1 = _OID(c_TwoCurve, 5) 210 c2tnb191v2 = _OID(c_TwoCurve, 6) 211 c2tnb191v3 = _OID(c_TwoCurve, 7) 212 c2onb191v4 = _OID(c_TwoCurve, 8) 213 c2onb191v5 = _OID(c_TwoCurve, 9) 214 c2pnb208w1 = _OID(c_TwoCurve, 10) 215 c2tnb239v1 = _OID(c_TwoCurve, 11) 216 c2tnb239v2 = _OID(c_TwoCurve, 12) 217 c2tnb239v3 = _OID(c_TwoCurve, 13) 218 c2onb239v4 = _OID(c_TwoCurve, 14) 219 c2onb239v5 = _OID(c_TwoCurve, 15) 220 c2pnb272w1 = _OID(c_TwoCurve, 16) 221 c2pnb304w1 = _OID(c_TwoCurve, 17) 222 c2tnb359v1 = _OID(c_TwoCurve, 18) 223 c2pnb368w1 = _OID(c_TwoCurve, 19) 224 c2tnb431r1 = _OID(c_TwoCurve, 20) 225 226 primeCurve = _OID(ellipticCurve, 1) 227 prime192v1 = _OID(primeCurve, 1) 228 prime192v2 = _OID(primeCurve, 2) 229 prime192v3 = _OID(primeCurve, 3) 230 prime239v1 = _OID(primeCurve, 4) 231 prime239v2 = _OID(primeCurve, 5) 232 prime239v3 = _OID(primeCurve, 6) 233 prime256v1 = _OID(primeCurve, 7) 234