Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
| 14 | """ |
Alex Gaynor | 1fe70b1 | 2013-10-16 11:59:17 -0700 | [diff] [blame] | 15 | Tests using the CRYPTREC (Camellia) Test Vectors |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 16 | """ |
| 17 | |
| 18 | from __future__ import absolute_import, division, print_function |
| 19 | |
| 20 | import binascii |
Alex Gaynor | 016eed1 | 2013-10-16 14:16:04 -0700 | [diff] [blame] | 21 | import os |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 22 | |
Alex Gaynor | 1fe70b1 | 2013-10-16 11:59:17 -0700 | [diff] [blame] | 23 | from cryptography.primitives.block import ciphers, modes |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 24 | |
Alex Gaynor | 1fe70b1 | 2013-10-16 11:59:17 -0700 | [diff] [blame] | 25 | from .utils import generate_encrypt_test |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 26 | from ..utils import load_cryptrec_vectors_from_file |
| 27 | |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 28 | |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 29 | class TestCamelliaECB(object): |
Alex Gaynor | 1fe70b1 | 2013-10-16 11:59:17 -0700 | [diff] [blame] | 30 | test_NTT = generate_encrypt_test( |
| 31 | load_cryptrec_vectors_from_file, |
Alex Gaynor | 016eed1 | 2013-10-16 14:16:04 -0700 | [diff] [blame] | 32 | os.path.join("Camellia", "NTT"), |
Alex Gaynor | 745c95c | 2013-10-16 14:41:35 -0700 | [diff] [blame] | 33 | [ |
| 34 | "camellia-128-ecb.txt", |
| 35 | "camellia-192-ecb.txt", |
| 36 | "camellia-256-ecb.txt" |
| 37 | ], |
Alex Gaynor | 1fe70b1 | 2013-10-16 11:59:17 -0700 | [diff] [blame] | 38 | lambda key: ciphers.Camellia(binascii.unhexlify((key))), |
Alex Gaynor | f55da9d | 2013-10-16 14:33:19 -0700 | [diff] [blame] | 39 | lambda key: modes.ECB(), |
Alex Gaynor | 512dd69 | 2013-10-16 14:27:52 -0700 | [diff] [blame] | 40 | only_if=lambda api: api.supports_cipher("camellia-128-ecb"), |
| 41 | skip_message="Does not support Camellia ECB", |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame] | 42 | ) |