summaryrefstree
path: root/kernel/scripts/crypto/fips_crypto_integrity.py
blob: f658475d968c5d158d76732cd13937d4937bf063 (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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
This script is needed for buildtime integrity routine.
It calculates and embeds HMAC and other needed stuff for in terms of FIPS 140-2
"""
import os
import sys
from IntegrityRoutine import IntegrityRoutine
from Utils import Utils

__author__ = "Vadym Stupakov"
__copyright__ = "Copyright (c) 2017 Samsung Electronics"
__credits__ = ["Vadym Stupakov"]
__version__ = "1.0"
__maintainer__ = "Vadym Stupakov"
__email__ = "v.stupakov@samsung.com"
__status__ = "Production"

list_obj_files_skc = [
    "fips140_integrity.o",
    "fips140_post.o",
    "fips140_test.o",
    "fips140_test_tv.o",
    "ghash-generic.o",
    "api.o",
    "cipher.o",
    "compress.o",
    "memneq.o",
    "proc.o",
    "algapi.o",
    "scatterwalk.o",
    "aead.o",
    "ablkcipher.o",
    "blkcipher.o",
    "skcipher.o",
    "seqiv.o",
    "echainiv.o",
    "ahash.o",
    "shash.o",
    "algboss.o",
    "testmgr.o",
    "hmac.o",
    "sha1_generic.o",
    "sha256_generic.o",
    "sha512_generic.o",
    "ecb.o",
    "cbc.o",
    "ctr.o",
    "gcm.o",
    "aes_generic.o",
    "authenc.o",
    "authencesn.o",
    "rng.o",
    "drbg.o",
    "jitterentropy.o",
    "jitterentropy-kcapi.o",
    "../lib/crypto/aes.o",
    "../lib/crypto/sha256.o"
]

list_obj_files_skc_ce = [
    "aes-ce-core.o",
    "aes-ce-glue.o",
    "aes-ce.o",
    "aes-cipher-core.o",
    "aes-cipher-glue.o",
    "aes-glue-ce.o",
    "sha256-core.o",
    "sha256-glue.o",
    "sha2-ce-core.o",
    "sha2-ce-glue.o",
    "sha1-ce-glue.o",
    "sha1-ce-core.o"
]

def find_first_obj_file(path_to_obj_files):
    file_obj_name = None
    for directory_file_list in path_to_obj_files:
        path_to_files = directory_file_list[0]
        for l_file in directory_file_list[1]:
            if os.path.isfile(os.path.join(path_to_files, l_file)):
                file_obj_name = os.path.join(path_to_files, l_file)
                break
        if file_obj_name is not None:
            break
    return file_obj_name

module_name = "crypto"

if __name__ == "__main__":

    if len(sys.argv) != 4:
        print("Usage {} [elf_file] [path to SKC *.o files] [path to SKC-CE *.o files]".format(sys.argv[0]))
        sys.exit(-1)

    print("module_name: ", module_name)

    elf_file = os.path.abspath(sys.argv[1])
    relative_path_to_skc_obj = sys.argv[2]
    relative_path_to_skc_ce_obj = sys.argv[3]

    utils = Utils()
    utils.paths_exists([elf_file])

    obj_files_full_path = [
                           [relative_path_to_skc_obj, list_obj_files_skc],
                           [relative_path_to_skc_ce_obj, list_obj_files_skc_ce]
                          ]

    first_obj_file = find_first_obj_file(obj_files_full_path)

    if first_obj_file is not None:
        integrity = IntegrityRoutine(elf_file, first_obj_file)
        sec_sym = integrity.get_filtered_canister_symbols(obj_files_full_path, debug=True)
        integrity.make_integrity(sec_sym=sec_sym, module_name=module_name, debug=False, print_reloc_gaps=False)
    else:
        print("ERROR: no OBJs files for parsing")
        sys.exit(-1)