Chia-Wei Wang | 6e84474 | 2021-07-30 09:08:03 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (c) 2021 ASPEED Technology Inc. |
| 4 | */ |
| 5 | #ifndef _UBOOT_HASH_H |
| 6 | #define _UBOOT_HASH_H |
| 7 | |
| 8 | enum HASH_ALGO { |
| 9 | HASH_ALGO_CRC16_CCITT, |
| 10 | HASH_ALGO_CRC32, |
| 11 | HASH_ALGO_MD5, |
| 12 | HASH_ALGO_SHA1, |
| 13 | HASH_ALGO_SHA256, |
| 14 | HASH_ALGO_SHA384, |
| 15 | HASH_ALGO_SHA512, |
| 16 | |
| 17 | HASH_ALGO_NUM, |
| 18 | |
| 19 | HASH_ALGO_INVALID = 0xffffffff, |
| 20 | }; |
| 21 | |
| 22 | /* general APIs for hash algo information */ |
| 23 | enum HASH_ALGO hash_algo_lookup_by_name(const char *name); |
| 24 | ssize_t hash_algo_digest_size(enum HASH_ALGO algo); |
| 25 | const char *hash_algo_name(enum HASH_ALGO algo); |
| 26 | |
| 27 | /* device-dependent APIs */ |
| 28 | int hash_digest(struct udevice *dev, enum HASH_ALGO algo, |
| 29 | const void *ibuf, const uint32_t ilen, |
| 30 | void *obuf); |
| 31 | int hash_digest_wd(struct udevice *dev, enum HASH_ALGO algo, |
| 32 | const void *ibuf, const uint32_t ilen, |
| 33 | void *obuf, uint32_t chunk_sz); |
| 34 | int hash_init(struct udevice *dev, enum HASH_ALGO algo, void **ctxp); |
| 35 | int hash_update(struct udevice *dev, void *ctx, const void *ibuf, const uint32_t ilen); |
| 36 | int hash_finish(struct udevice *dev, void *ctx, void *obuf); |
| 37 | |
| 38 | /* |
| 39 | * struct hash_ops - Driver model for Hash operations |
| 40 | * |
| 41 | * The uclass interface is implemented by all hash devices |
| 42 | * which use driver model. |
| 43 | */ |
| 44 | struct hash_ops { |
| 45 | /* progressive operations */ |
| 46 | int (*hash_init)(struct udevice *dev, enum HASH_ALGO algo, void **ctxp); |
| 47 | int (*hash_update)(struct udevice *dev, void *ctx, const void *ibuf, const uint32_t ilen); |
| 48 | int (*hash_finish)(struct udevice *dev, void *ctx, void *obuf); |
| 49 | |
| 50 | /* all-in-one operation */ |
| 51 | int (*hash_digest)(struct udevice *dev, enum HASH_ALGO algo, |
| 52 | const void *ibuf, const uint32_t ilen, |
| 53 | void *obuf); |
| 54 | |
| 55 | /* all-in-one operation with watchdog triggering every chunk_sz */ |
| 56 | int (*hash_digest_wd)(struct udevice *dev, enum HASH_ALGO algo, |
| 57 | const void *ibuf, const uint32_t ilen, |
| 58 | void *obuf, uint32_t chunk_sz); |
| 59 | }; |
| 60 | |
| 61 | #endif |