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
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2011 The Chromium OS Authors.
* (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
*/
#include <dm.h>
#include <log.h>
#include <linux/errno.h>
#include <asm/arch-tegra/crypto.h>
#include "uboot_aes.h"
int sign_data_block(u8 *source, unsigned int length, u8 *signature)
{
struct udevice *dev;
int ret;
/* Only one AES engine should be present */
ret = uclass_get_device(UCLASS_AES, 0, &dev);
if (ret) {
log_err("%s: failed to get tegra_aes: %d\n", __func__, ret);
return ret;
}
ret = dm_aes_select_key_slot(dev, 128, TEGRA_AES_SLOT_SBK);
if (ret)
return ret;
return dm_aes_cmac(dev, source, signature,
DIV_ROUND_UP(length, AES_BLOCK_LENGTH));
}
int encrypt_data_block(u8 *source, u8 *dest, unsigned int length)
{
struct udevice *dev;
int ret;
/* Only one AES engine should be present */
ret = uclass_get_device(UCLASS_AES, 0, &dev);
if (ret) {
log_err("%s: failed to get tegra_aes: %d\n", __func__, ret);
return ret;
}
ret = dm_aes_select_key_slot(dev, 128, TEGRA_AES_SLOT_SBK);
if (ret)
return ret;
return dm_aes_cbc_encrypt(dev, (u8 *)AES_ZERO_BLOCK, source, dest,
DIV_ROUND_UP(length, AES_BLOCK_LENGTH));
}
int decrypt_data_block(u8 *source, u8 *dest, unsigned int length)
{
struct udevice *dev;
int ret;
/* Only one AES engine should be present */
ret = uclass_get_device(UCLASS_AES, 0, &dev);
if (ret) {
log_err("%s: failed to get tegra_aes: %d\n", __func__, ret);
return ret;
}
ret = dm_aes_select_key_slot(dev, 128, TEGRA_AES_SLOT_SBK);
if (ret)
return ret;
return dm_aes_cbc_decrypt(dev, (u8 *)AES_ZERO_BLOCK, source, dest,
DIV_ROUND_UP(length, AES_BLOCK_LENGTH));
}
|