-
Notifications
You must be signed in to change notification settings - Fork 0
/
_key_types.py
143 lines (136 loc) · 5.22 KB
/
_key_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This file gives an overview of the key types supported in Tink.
This file is the authorative reference of which key types Tink currently
understands in which language, and for which primitive. The correctness of this
file is checked by the cross language tests.
"""
from tink import aead
from tink import daead
from tink import hybrid
from tink import jwt
from tink import mac
from tink import prf
from tink import signature
from tink import streaming_aead
# Map from the primitives to the KeyTypes (without the prefix
# 'type.googleapis.com/google.crypto.tink.')
KEY_TYPES = {
aead.Aead: (
'AesCtrHmacAeadKey',
'AesEaxKey',
'AesGcmKey',
'AesGcmSivKey',
'ChaCha20Poly1305Key',
'KmsAeadKey',
'KmsEnvelopeAeadKey',
'XChaCha20Poly1305Key',
),
daead.DeterministicAead: ('AesSivKey',),
streaming_aead.StreamingAead: (
'AesCtrHmacStreamingKey',
'AesGcmHkdfStreamingKey',
),
hybrid.HybridDecrypt: ('EciesAeadHkdfPrivateKey', 'HpkePrivateKey'),
hybrid.HybridEncrypt: ('EciesAeadHkdfPublicKey', 'HpkePublicKey'),
jwt.JwtMac: ('JwtHmacKey',),
jwt.JwtPublicKeySign: (
'JwtEcdsaPrivateKey',
'JwtRsaSsaPkcs1PrivateKey',
'JwtRsaSsaPssPrivateKey',
),
jwt.JwtPublicKeyVerify: (
'JwtEcdsaPublicKey',
'JwtRsaSsaPkcs1PublicKey',
'JwtRsaSsaPssPublicKey',
),
mac.Mac: (
'AesCmacKey',
'HmacKey',
),
prf.PrfSet: (
'AesCmacPrfKey',
'HmacPrfKey',
'HkdfPrfKey',
),
signature.PublicKeySign: (
'EcdsaPrivateKey',
'Ed25519PrivateKey',
'RsaSsaPkcs1PrivateKey',
'RsaSsaPssPrivateKey',
),
signature.PublicKeyVerify: (
'EcdsaPublicKey',
'Ed25519PublicKey',
'RsaSsaPkcs1PublicKey',
'RsaSsaPssPublicKey',
),
}
# Map from Asymmetric Private Primitive to Asymmetric Public Primitive
PRIVATE_TO_PUBLIC_PRIMITIVE = {
hybrid.HybridDecrypt: hybrid.HybridEncrypt,
signature.PublicKeySign: signature.PublicKeyVerify,
jwt.JwtPublicKeySign: jwt.JwtPublicKeyVerify,
}
# Map from Private Key Types to Public Key Types
PRIVATE_TO_PUBLIC_KEY = {
'EciesAeadHkdfPrivateKey': 'EciesAeadHkdfPublicKey',
'HpkePrivateKey': 'HpkePublicKey',
'EcdsaPrivateKey': 'EcdsaPublicKey',
'Ed25519PrivateKey': 'Ed25519PublicKey',
'RsaSsaPkcs1PrivateKey': 'RsaSsaPkcs1PublicKey',
'RsaSsaPssPrivateKey': 'RsaSsaPssPublicKey',
'JwtEcdsaPrivateKey': 'JwtEcdsaPublicKey',
'JwtRsaSsaPkcs1PrivateKey': 'JwtRsaSsaPkcs1PublicKey',
'JwtRsaSsaPssPrivateKey': 'JwtRsaSsaPssPublicKey',
}
ALL_LANGUAGES = ['cc', 'java', 'go', 'python']
# All languages that are supported by a KeyType
SUPPORTED_LANGUAGES = {
'AesEaxKey': ['cc', 'java', 'python'],
'AesGcmKey': ['cc', 'java', 'go', 'python'],
'AesGcmSivKey': ['cc', 'java', 'go', 'python'],
'AesCtrHmacAeadKey': ['cc', 'java', 'go', 'python'],
'ChaCha20Poly1305Key': ['java', 'go'],
'XChaCha20Poly1305Key': ['cc', 'java', 'go', 'python'],
'KmsAeadKey': ['cc', 'java', 'go', 'python'], # go only supported in tests.
'KmsEnvelopeAeadKey': ['cc', 'java', 'go', 'python'],
'AesSivKey': ['cc', 'java', 'go', 'python'],
'AesCtrHmacStreamingKey': ['cc', 'java', 'go', 'python'],
'AesGcmHkdfStreamingKey': ['cc', 'java', 'go', 'python'],
'EciesAeadHkdfPrivateKey': ['cc', 'java', 'go', 'python'],
'EciesAeadHkdfPublicKey': ['cc', 'java', 'go', 'python'],
'HpkePrivateKey': ['cc', 'java', 'go', 'python'],
'HpkePublicKey': ['cc', 'java', 'go', 'python'],
'AesCmacKey': ['cc', 'java', 'go', 'python'],
'HmacKey': ['cc', 'java', 'go', 'python'],
'EcdsaPrivateKey': ['cc', 'java', 'go', 'python'],
'EcdsaPublicKey': ['cc', 'java', 'go', 'python'],
'Ed25519PrivateKey': ['cc', 'java', 'go', 'python'],
'Ed25519PublicKey': ['cc', 'java', 'go', 'python'],
'RsaSsaPkcs1PrivateKey': ['cc', 'java', 'go', 'python'],
'RsaSsaPkcs1PublicKey': ['cc', 'java', 'go', 'python'],
'RsaSsaPssPrivateKey': ['cc', 'java', 'go', 'python'],
'RsaSsaPssPublicKey': ['cc', 'java', 'go', 'python'],
'AesCmacPrfKey': ['cc', 'java', 'go', 'python'],
'HmacPrfKey': ['cc', 'java', 'go', 'python'],
'HkdfPrfKey': ['cc', 'java', 'go', 'python'],
'JwtHmacKey': ['cc', 'java', 'go', 'python'],
'JwtEcdsaPrivateKey': ['cc', 'java', 'go', 'python'],
'JwtEcdsaPublicKey': ['cc', 'java', 'go', 'python'],
'JwtRsaSsaPkcs1PrivateKey': ['cc', 'java', 'go', 'python'],
'JwtRsaSsaPkcs1PublicKey': ['cc', 'java', 'go', 'python'],
'JwtRsaSsaPssPrivateKey': ['cc', 'java', 'go', 'python'],
'JwtRsaSsaPssPublicKey': ['cc', 'java', 'go', 'python'],
}