Browse Source
This patch adds RNG driver and use it to generate random number for stack protection. Change-Id: I73d79e68d08b5aa902dc7fad48e17a03f996178d Signed-off-by: Saurabh Gorecha <sgorecha@codeaurora.org>pull/1979/head
Saurabh Gorecha
4 years ago
committed by
joanna.farley
7 changed files with 90 additions and 17 deletions
@ -0,0 +1,14 @@ |
|||
/*
|
|||
* Copyright (c) 2020, The Linux Foundation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#ifndef QTI_RNG_H |
|||
#define QTI_RNG_H |
|||
|
|||
#include <stdinit.h> |
|||
|
|||
int qti_rng_get_data(uint8_t *out, uint32_t out_len); |
|||
|
|||
#endif /* QTI_RNG_H */ |
@ -0,0 +1,53 @@ |
|||
/*
|
|||
* Copyright (c) 2020, The Linux Foundation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
#include <stddef.h> |
|||
#include <stdint.h> |
|||
|
|||
#include <lib/mmio.h> |
|||
|
|||
#include <qti_rng_io.h> |
|||
|
|||
int qti_rng_get_data(uint8_t *out, uint32_t out_len) |
|||
{ |
|||
uint32_t tmp_rndm = 0; |
|||
uint32_t bytes_left = out_len; |
|||
int i = 0; |
|||
|
|||
if (NULL == out || 0 == out_len) { |
|||
return -1; |
|||
} |
|||
|
|||
/*
|
|||
* RNG HW initialized at previous boot image. |
|||
* RNG clocks are expected to be ON. |
|||
*/ |
|||
|
|||
do { |
|||
/* There is no data to read */ |
|||
if ((mmio_read_32(SEC_PRNG_STATUS) & |
|||
SEC_PRNG_STATUS_DATA_AVAIL_BMSK) == 0) { |
|||
continue; |
|||
} |
|||
|
|||
while ((tmp_rndm = mmio_read_32(SEC_PRNG_DATA_OUT)) == 0) { |
|||
; |
|||
} |
|||
|
|||
for (i = 0; i < 4; i++) { |
|||
*out = (uint8_t) (tmp_rndm >> (8 * i)); |
|||
|
|||
out++; |
|||
bytes_left--; |
|||
|
|||
if (bytes_left == 0) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
} while (bytes_left != 0); |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,15 @@ |
|||
/*
|
|||
* Copyright (c) 2020, The Linux Foundation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
#ifndef QTI_RNG_IO_H |
|||
#define QTI_RNG_IO_H |
|||
|
|||
#define SEC_PRNG_STATUS 0x00791004 |
|||
#define SEC_PRNG_STATUS_DATA_AVAIL_BMSK 0x1 |
|||
#define SEC_PRNG_DATA_OUT 0x00791000 |
|||
|
|||
|
|||
#endif /* QTI_RNG_IO_H */ |
|||
|
Loading…
Reference in new issue