Commit d9dff00a authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

more headers

parent 17fc625b
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* (C) Copyright 2009
* Marvell Semiconductor <www.marvell.com>
* Written-by: Prafulla Wadaskar <prafulla@marvell.com>
*/
#ifndef _UBOOT_CRC_H
#define _UBOOT_CRC_H
/* lib/crc8.c */
unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len);
/* lib/crc16.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */
uint16_t crc16_ccitt(uint16_t crc_start, const unsigned char *s, int len);
/**
* crc16_ccitt_wd_buf - Perform CRC16-CCIT on an input buffer and return the
* 16-bit result (network byte-order) in an output buffer
*
* @in: input buffer
* @len: input buffer length
* @out: output buffer (at least 2 bytes)
* @chunk_sz: ignored
*/
void crc16_ccitt_wd_buf(const uint8_t *in, uint len,
uint8_t *out, uint chunk_sz);
/* lib/crc32.c */
uint32_t crc32 (uint32_t, const unsigned char *, uint);
uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
/**
* crc32_wd_buf - Perform CRC32 on a buffer and return result in buffer
*
* @input: Input buffer
* @ilen: Input buffer length
* @output: Place to put checksum result (4 bytes)
* @chunk_sz: Trigger watchdog after processing this many bytes
*/
void crc32_wd_buf(const unsigned char *input, uint ilen,
unsigned char *output, uint chunk_sz);
/* lib/crc32c.c */
void crc32c_init(uint32_t *, uint32_t);
uint32_t crc32c_cal(uint32_t, const char *, int, uint32_t *);
#endif /* _UBOOT_CRC_H */
/*
* This file was transplanted with slight modifications from Linux sources
* (fs/cifs/md5.h) into U-Boot by Bartlomiej Sieka <tur@semihalf.com>.
*/
#ifndef _MD5_H
#define _MD5_H
#include "compiler.h"
struct MD5Context {
__u32 buf[4];
__u32 bits[2];
union {
unsigned char in[64];
__u32 in32[16];
};
};
/*
* Calculate and store in 'output' the MD5 digest of 'len' bytes at
* 'input'. 'output' must have enough space to hold 16 bytes.
*/
void md5 (unsigned char *input, int len, unsigned char output[16]);
/*
* Calculate and store in 'output' the MD5 digest of 'len' bytes at 'input'.
* 'output' must have enough space to hold 16 bytes. If 'chunk' Trigger the
* watchdog every 'chunk_sz' bytes of input processed.
*/
void md5_wd (unsigned char *input, int len, unsigned char output[16],
unsigned int chunk_sz);
#endif /* _MD5_H */
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2013, Andreas Oetken.
*/
#ifndef _RSA_CHECKSUM_H
#define _RSA_CHECKSUM_H
#include <errno.h>
#include <image.h>
#include <u-boot/sha1.h>
#include <u-boot/sha256.h>
/**
* hash_calculate() - Calculate hash over the data
*
* @name: Name of algorithm to be used for hash calculation
* @region: Array having info of regions over which hash needs to be calculated
* @region_count: Number of regions in the region array
* @checksum: Buffer contanining the output hash
*
* @return 0 if OK, < 0 if error
*/
int hash_calculate(const char *name,
const struct image_region region[], int region_count,
uint8_t *checksum);
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright 2014 Freescale Semiconductor, Inc.
*/
#ifndef _RSA_MOD_EXP_H
#define _RSA_MOD_EXP_H
#include <errno.h>
#include <image.h>
/**
* struct key_prop - holder for a public key properties
*
* The struct has pointers to modulus (Typically called N),
* The inverse, R^2, exponent. These can be typecasted and
* used as byte arrays or converted to the required format
* as per requirement of RSA implementation.
*/
struct key_prop {
const void *rr; /* R^2 can be treated as byte array */
const void *modulus; /* modulus as byte array */
const void *public_exponent; /* public exponent as byte array */
uint32_t n0inv; /* -1 / modulus[0] mod 2^32 */
int num_bits; /* Key length in bits */
uint32_t exp_len; /* Exponent length in number of uint8_t */
};
/**
* rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw
*
* Operation: out[] = sig ^ exponent % modulus
*
* @sig: RSA PKCS1.5 signature
* @sig_len: Length of signature in number of bytes
* @node: Node with RSA key elements like modulus, exponent, R^2, n0inv
* @out: Result in form of byte array of len equal to sig_len
*/
int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
struct key_prop *node, uint8_t *out);
int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
struct key_prop *node, uint8_t *out);
#if defined(CONFIG_CMD_ZYNQ_RSA)
int zynq_pow_mod(u32 *keyptr, u32 *inout);
#endif
/**
* struct struct mod_exp_ops - Driver model for RSA Modular Exponentiation
* operations
*
* The uclass interface is implemented by all crypto devices which use
* driver model.
*/
struct mod_exp_ops {
/**
* Perform Modular Exponentiation
*
* Operation: out[] = sig ^ exponent % modulus
*
* @dev: RSA Device
* @sig: RSA PKCS1.5 signature
* @sig_len: Length of signature in number of bytes
* @node: Node with RSA key elements like modulus, exponent,
* R^2, n0inv
* @out: Result in form of byte array of len equal to sig_len
*
* This function computes exponentiation over the signature.
* Returns: 0 if exponentiation is successful, or a negative value
* if it wasn't.
*/
int (*mod_exp)(struct udevice *dev, const uint8_t *sig,
uint32_t sig_len, struct key_prop *node,
uint8_t *outp);
};
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2013, Google Inc.
*
* (C) Copyright 2008 Semihalf
*
* (C) Copyright 2000-2006
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#ifndef _RSA_H
#define _RSA_H
#include <errno.h>
#include <image.h>
/**
* struct rsa_public_key - holder for a public key
*
* An RSA public key consists of a modulus (typically called N), the inverse
* and R^2, where R is 2^(# key bits).
*/
struct rsa_public_key {
uint len; /* len of modulus[] in number of uint32_t */
uint32_t n0inv; /* -1 / modulus[0] mod 2^32 */
uint32_t *modulus; /* modulus as little endian array */
uint32_t *rr; /* R^2 as little endian array */
uint64_t exponent; /* public exponent */
};
struct image_sign_info;
#if IMAGE_ENABLE_SIGN
/**
* sign() - calculate and return signature for given input data
*
* @info: Specifies key and FIT information
* @data: Pointer to the input data
* @data_len: Data length
* @sigp: Set to an allocated buffer holding the signature
* @sig_len: Set to length of the calculated hash
*
* This computes input data signature according to selected algorithm.
* Resulting signature value is placed in an allocated buffer, the
* pointer is returned as *sigp. The length of the calculated
* signature is returned via the sig_len pointer argument. The caller
* should free *sigp.
*
* @return: 0, on success, -ve on error
*/
int rsa_sign(struct image_sign_info *info,
const struct image_region region[],
int region_count, uint8_t **sigp, uint *sig_len);
/**
* add_verify_data() - Add verification information to FDT
*
* Add public key information to the FDT node, suitable for
* verification at run-time. The information added depends on the
* algorithm being used.
*
* @info: Specifies key and FIT information
* @keydest: Destination FDT blob for public key data
* @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
other -ve value on error
*/
int rsa_add_verify_data(struct image_sign_info *info, void *keydest);
#else
static inline int rsa_sign(struct image_sign_info *info,
const struct image_region region[], int region_count,
uint8_t **sigp, uint *sig_len)
{
return -ENXIO;
}
static inline int rsa_add_verify_data(struct image_sign_info *info,
void *keydest)
{
return -ENXIO;
}
#endif
#if IMAGE_ENABLE_VERIFY
/**
* rsa_verify() - Verify a signature against some data
*
* Verify a RSA PKCS1.5 signature against an expected hash.
*
* @info: Specifies key and FIT information
* @data: Pointer to the input data
* @data_len: Data length
* @sig: Signature
* @sig_len: Number of bytes in signature
* @return 0 if verified, -ve on error
*/
int rsa_verify(struct image_sign_info *info,
const struct image_region region[], int region_count,
uint8_t *sig, uint sig_len);
int padding_pkcs_15_verify(struct image_sign_info *info,
uint8_t *msg, int msg_len,
const uint8_t *hash, int hash_len);
#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
int padding_pss_verify(struct image_sign_info *info,
uint8_t *msg, int msg_len,
const uint8_t *hash, int hash_len);
#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
#else
static inline int rsa_verify(struct image_sign_info *info,
const struct image_region region[], int region_count,
uint8_t *sig, uint sig_len)
{
return -ENXIO;
}
static inline int padding_pkcs_15_verify(struct image_sign_info *info,
uint8_t *msg, int msg_len,
const uint8_t *hash, int hash_len)
{
return -ENXIO;
}
#ifdef CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT
static inline int padding_pss_verify(struct image_sign_info *info,
uint8_t *msg, int msg_len,
const uint8_t *hash, int hash_len)
{
return -ENXIO;
}
#endif /* CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT */
#endif
#define RSA_DEFAULT_PADDING_NAME "pkcs-1.5"
#define RSA2048_BYTES (2048 / 8)
#define RSA4096_BYTES (4096 / 8)
/* This is the minimum/maximum key size we support, in bits */
#define RSA_MIN_KEY_BITS 2048
#define RSA_MAX_KEY_BITS 4096
/* This is the maximum signature length that we support, in bits */
#define RSA_MAX_SIG_BITS 4096
#endif
/*
* Linker script helper macros
*
* Copyright (c) 2009 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
#ifndef __U_BOOT_LDS__
#define __U_BOOT_LDS__
/* See if the linker version is at least the specified version */
#define LD_AT_LEAST(major, minor) \
((major > LD_MAJOR) || (major == LD_MAJOR && minor <= LD_MINOR))
/*
* Linker versions prior to 2.16 don't understand the builtin
* functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
*/
#if !LD_AT_LEAST(2, 16)
# define SORT_BY_ALIGNMENT(x) x
# define SORT_BY_NAME(x) x
#endif
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Helper for work with variadic macros
*
* 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
*/
#ifndef __VARIADIC_MACRO_H__
#define __VARIADIC_MACRO_H__
#define _VM_GET_NTH_ARG(_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, N, ...) N
#define _VM_HELP_0(_call, ...)
#define _VM_HELP_1(_call, x, ...) _call(x)
#define _VM_HELP_2(_call, x, ...) _call(x) _VM_HELP_1(_call, __VA_ARGS__)
#define _VM_HELP_3(_call, x, ...) _call(x) _VM_HELP_2(_call, __VA_ARGS__)
#define _VM_HELP_4(_call, x, ...) _call(x) _VM_HELP_3(_call, __VA_ARGS__)
#define _VM_HELP_5(_call, x, ...) _call(x) _VM_HELP_4(_call, __VA_ARGS__)
#define _VM_HELP_6(_call, x, ...) _call(x) _VM_HELP_5(_call, __VA_ARGS__)
#define _VM_HELP_7(_call, x, ...) _call(x) _VM_HELP_6(_call, __VA_ARGS__)
#define _VM_HELP_8(_call, x, ...) _call(x) _VM_HELP_7(_call, __VA_ARGS__)
#define _VM_HELP_9(_call, x, ...) _call(x) _VM_HELP_8(_call, __VA_ARGS__)
#define _VM_HELP_10(_call, x, ...) _call(x) _VM_HELP_9(_call, __VA_ARGS__)
#define _VM_HELP_11(_call, x, ...) _call(x) _VM_HELP_10(_call, __VA_ARGS__)
#define _VM_HELP_12(_call, x, ...) _call(x) _VM_HELP_11(_call, __VA_ARGS__)
#define _VM_HELP_13(_call, x, ...) _call(x) _VM_HELP_12(_call, __VA_ARGS__)
#define _VM_HELP_14(_call, x, ...) _call(x) _VM_HELP_13(_call, __VA_ARGS__)
#define _VM_HELP_15(_call, x, ...) _call(x) _VM_HELP_14(_call, __VA_ARGS__)
#define _VM_HELP_16(_call, x, ...) _call(x) _VM_HELP_15(_call, __VA_ARGS__)
#define _VM_HELP_17(_call, x, ...) _call(x) _VM_HELP_16(_call, __VA_ARGS__)
#define _VM_HELP_18(_call, x, ...) _call(x) _VM_HELP_17(_call, __VA_ARGS__)
#define _VM_HELP_19(_call, x, ...) _call(x) _VM_HELP_18(_call, __VA_ARGS__)
#define _VM_HELP_20(_call, x, ...) _call(x) _VM_HELP_19(_call, __VA_ARGS__)
#define _VM_HELP_21(_call, x, ...) _call(x) _VM_HELP_20(_call, __VA_ARGS__)
#define _VM_HELP_22(_call, x, ...) _call(x) _VM_HELP_21(_call, __VA_ARGS__)
#define _VM_HELP_23(_call, x, ...) _call(x) _VM_HELP_22(_call, __VA_ARGS__)
#define _VM_HELP_24(_call, x, ...) _call(x) _VM_HELP_23(_call, __VA_ARGS__)
#define _VM_HELP_25(_call, x, ...) _call(x) _VM_HELP_24(_call, __VA_ARGS__)
#define _VM_HELP_26(_call, x, ...) _call(x) _VM_HELP_25(_call, __VA_ARGS__)
#define _VM_HELP_27(_call, x, ...) _call(x) _VM_HELP_26(_call, __VA_ARGS__)
#define _VM_HELP_28(_call, x, ...) _call(x) _VM_HELP_27(_call, __VA_ARGS__)
#define _VM_HELP_29(_call, x, ...) _call(x) _VM_HELP_28(_call, __VA_ARGS__)
#define _VM_HELP_30(_call, x, ...) _call(x) _VM_HELP_29(_call, __VA_ARGS__)
#define _VM_HELP_31(_call, x, ...) _call(x) _VM_HELP_30(_call, __VA_ARGS__)
#define CALL_MACRO_FOR_EACH(x, ...) \
_VM_GET_NTH_ARG("", ##__VA_ARGS__, _VM_HELP_31, _VM_HELP_30, \
_VM_HELP_29, _VM_HELP_28, _VM_HELP_27, _VM_HELP_26, _VM_HELP_25, \
_VM_HELP_24, _VM_HELP_23, _VM_HELP_22, _VM_HELP_21, _VM_HELP_20, \
_VM_HELP_19, _VM_HELP_18, _VM_HELP_17, _VM_HELP_16, _VM_HELP_15, \
_VM_HELP_14, _VM_HELP_13, _VM_HELP_12, _VM_HELP_11, _VM_HELP_10, \
_VM_HELP_9, _VM_HELP_8, _VM_HELP_7, _VM_HELP_6, _VM_HELP_5, \
_VM_HELP_4, _VM_HELP_3, _VM_HELP_2, _VM_HELP_1, \
_VM_HELP_0)(x, __VA_ARGS__)
#endif /* __VARIADIC_MACRO_H__ */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment