library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity foo is constant m: integer := 3; constant n: integer := 5; constant h: integer := 4; constant DATA_SIZE: integer :=5; end entity; architecture fum of foo is signal OUTPUT : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0) := "000011110110" ; type Vector is record OUTPUT_test : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0); end record; type VectorArray is array (natural range <>) of Vector; constant Vectors : VectorArray := ( -- Values to be compaired to calculated output (OUTPUT_test =>"000011110110"), -- 246 (CORRECT) (OUTPUT_test =>"000101001000") -- 382 (INCORRECT) ); begin TEST: process begin for i in Vectors'RANGE loop assert OUTPUT = Vectors(i).OUTPUT_test report "Incorrect Output on vector line " & integer'image(i) & -- lf & "Expected:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_test))) lf & "Expected:" & integer'image(to_integer((Vectors(i).OUTPUT_test))) severity error; end loop; wait; end process; end architecture; input type='submit' value='switch'/> python cryptographyJames
aboutsummaryrefslogtreecommitdiffstats
path: root/docs/development/custom-vectors/seed/verify_seed.py
blob: e626428cb0c2e48ff1bcae58eaf8289c925e6365 (plain)
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
import binascii

import botan

from tests.utils import load_nist_vectors


def encrypt(mode, key, iv, plaintext):
    encryptor = botan.Cipher("SEED/{0}/NoPadding".format(mode), "encrypt",
                             binascii.unhexlify(key))

    cipher_text = encryptor.cipher(binascii.unhexlify(plaintext),
                                   binascii.unhexlify(iv))
    return binascii.hexlify(cipher_text)


def verify_vectors(mode, filename):
    with open(filename, "r") as f:
        vector_file = f.read().splitlines()

    vectors = load_nist_vectors(vector_file)
    for vector in vectors:
        ct = encrypt(
            mode,
            vector["key"],
            vector["iv"],
            vector["plaintext"]
        )
        assert ct == vector["ciphertext"]


ofb_path = "vectors/cryptography_vectors/ciphers/SEED/seed-ofb.txt"
verify_vectors("OFB", ofb_path)
cfb_path = "vectors/cryptography_vectors/ciphers/SEED/seed-cfb.txt"
verify_vectors("CFB", cfb_path)