summaryrefslogtreecommitdiff
path: root/drivers/mxc/security/sahara2/fsl_shw_rand.c
blob: 566c9e5c1e0f51fae09917c94913400c77e4b3b7 (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
/*
 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
 * @file fsl_shw_rand.c
 *
 * This file implements Random Number Generation functions of the FSL SHW API
 * for Sahara.
 */

#include "sahara.h"
#include "sf_util.h"

#ifdef __KERNEL__
EXPORT_SYMBOL(fsl_shw_get_random);
#endif

/* REQ-S2LRD-PINTFC-API-BASIC-RNG-002 */
/*!
 * Get a random number
 *
 *
 * @param    user_ctx
 * @param    length
 * @param    data
 *
 * @return    A return code of type #fsl_shw_return_t.
 */
fsl_shw_return_t fsl_shw_get_random(fsl_shw_uco_t * user_ctx,
				    uint32_t length, uint8_t * data)
{
	SAH_SF_DCLS;

	/* perform a sanity check on the uco */
	ret = sah_validate_uco(user_ctx);
	if (ret != FSL_RETURN_OK_S) {
		goto out;
	}

	header = SAH_HDR_RNG_GENERATE;	/* Desc. #18 */
	DESC_OUT_OUT(header, length, data, 0, NULL);

	SAH_SF_EXECUTE();

      out:
	SAH_SF_DESC_CLEAN();

	return ret;
}

#ifdef __KERNEL__
EXPORT_SYMBOL(fsl_shw_add_entropy);
#endif

/*!
 * Add entropy to a random number generator

 * @param    user_ctx
 * @param    length
 * @param    data
 *
 * @return    A return code of type #fsl_shw_return_t.
 */
fsl_shw_return_t fsl_shw_add_entropy(fsl_shw_uco_t * user_ctx,
				     uint32_t length, uint8_t * data)
{
	SAH_SF_DCLS;

	/* perform a sanity check on the uco */
	ret = sah_validate_uco(user_ctx);
	if (ret != FSL_RETURN_OK_S) {
		goto out;
	}

	header = SAH_HDR_RNG_GENERATE;	/* Desc. #18 */

	/* create descriptor #18. Generate random data */
	DESC_IN_IN(header, 0, NULL, length, data)

	    SAH_SF_EXECUTE();

      out:
	SAH_SF_DESC_CLEAN();

	return ret;
}