import x509/pkcs7 parsers from linux
Subsystems (9)
v3 cover import x509/pkcs7 parsers from linux
# This patch set is a prerequisite for UEFI secure boot.
# This patch set should be merged first prior to my rsa extension patch
# due to some dependency.
Asn1 parsers of x509 certificates and pkcs7 messages are required to implement image authentication and variable authentication as part of UEFI secure boot feature.
As we discussed before in the thread[1], most people insisted that we should re-use corresponding source code from Linux repository for this purpose.
Here is my attempt to import all the necessary files from Linux; Those will eventually be part of UEFI secure boot implementation, but I'd like to get early feedback from other peoples before submitting the whole patchset so that they will be better formatted for merging.
My approach here is
* files from the latest Linux
* modify files as little as possible
* mark/protect unavoidable changes with "#if(n)def __UBOOT__" so that future fixes/differences in Linux repository will easily be applied to U-Boot.
Known issues:
* checkpatch.pl
Checkpatch.pl will complain with a bunch of warnings/errors but I intentionally left them unchanged for the sake of better maintainability I said above.
-Takahiro Akashi
[1] https://lists.denx.de/pipermail/u-boot/2019-April/366423.html
Changes in v3 (Nov 13, 2019)
* rebased to v2020.01-rc
* improve function description of kmemdup() (patch#1)
* remove test/lib/Kconfig (patch#16)
* declare variables in unit test as static (patch#16)
Changes in v2 (Oct 25, 2019)
* revise commit messages, describing what files are modified or not.
* move kmemdump() in ubifs.c to linux_compat.c for general use (patch#1)
* add patch#2
* move date.c to lib/ for general use (patch#3)
* implement mktime64() with rtc_mktime() (patch#4)
* move asn1_compiler.c to tools/ (patch#7)
* change CONFIG_BUILD_ASN1 to CONFIG_ASN1_COMPILER (patch#7)
* add clean rule to asn1_compiler-generated files to clean targets (patch#8)
* change CONFIG_ASN1 to CONFIG_ASN1_DECODER (patch#9)
* add README for asn1 compiler/decoder (patch#10)
* move build_oid_registry to scripts/ (patch#11)
* shuffle an order of patches (patch#13,#14,#15)
* add a new config CONFIG_RSA_PUBLIC_KEY_PARSER so that it can be
* modify Kconfig dependency (patch#13,#14,#15)
compiled in independently (patch#13)
* add unit test (patch#16,#17)
Changes in v1 (Oct 11, 2019) from RFC
* change the kernel code base from v5.0 to v5.3
* add preparatory patches (#1, #2 and #3)
* comment off x509_check_for_self_signed() which is not useful for UEFI secure boot (patch#9)
* improve usages of "#if(n)def __UBOOT__* to minimize differences between U-Boot and linux kernel
AKASHI Takahiro (16):
linux_compat: move kmemdup() from ubifs.c to linux_compat.c rtc.h: add struct udevice declaration
rtc: move date.c from drivers/rtc/ to lib/
lib: add mktime64() for linux compatibility
include: kernel.h: include printk.h
linux/time.h: include vsprintf.h
cmd: add asn1_compiler
Makefile: add build script for asn1 parsers
lib: add asn1 decoder
doc: add README for asn1 compiler and decoder
lib: add oid registry utility
lib: crypto: add public key utility
lib: crypto: add rsa public key parser
lib: crypto: add x509 parser
lib: crypto: add pkcs7 message parser
test: add asn1 unit test
Makefile | 1 +
cmd/Kconfig | 1 +
doc/README.asn1 | 40 +
drivers/rtc/Kconfig | 1 +
drivers/rtc/Makefile | 1 -
fs/ubifs/ubifs.c | 19 +-
include/crypto/internal/rsa.h | 57 +
include/crypto/pkcs7.h | 47 +
include/crypto/public_key.h | 90 ++
include/keys/asymmetric-type.h | 88 ++
include/linux/asn1.h | 65 ++
include/linux/asn1_ber_bytecode.h | 89 ++
include/linux/asn1_decoder.h | 20 +
include/linux/kernel.h | 2 +-
include/linux/oid_registry.h | 117 +++
include/linux/time.h | 11 +
include/rtc.h | 2 +
lib/Kconfig | 17 +
lib/Makefile | 20 +
lib/asn1_decoder.c | 527 ++++++++++
lib/crypto/Kconfig | 52 +
lib/crypto/Makefile | 49 +
lib/crypto/asymmetric_type.c | 668 ++++++++++++
lib/crypto/pkcs7.asn1 | 135 +++
lib/crypto/pkcs7_parser.c | 693 +++++++++++++
lib/crypto/pkcs7_parser.h | 65 ++
lib/crypto/public_key.c | 376 +++++++
lib/crypto/rsa_helper.c | 198 ++++
lib/crypto/rsapubkey.asn1 | 4 +
lib/crypto/x509.asn1 | 60 ++
lib/crypto/x509_akid.asn1 | 35 +
lib/crypto/x509_cert_parser.c | 697 +++++++++++++
lib/crypto/x509_parser.h | 57 +
lib/crypto/x509_public_key.c | 292 ++++++
{drivers/rtc => lib}/date.c | 23 +-
lib/linux_compat.c | 19 +
lib/oid_registry.c | 179 ++++
scripts/Makefile.build | 4 +-
scripts/build_OID_registry | 203 ++++
test/Kconfig | 18 +-
test/lib/Makefile | 1 +
test/lib/asn1.c | 392 +++++++
tools/Makefile | 3 +
tools/asn1_compiler.c | 1611 +++++++++++++++++++++++++++++
44 files changed, 7024 insertions(+), 25 deletions(-)
create mode 100644 doc/README.asn1
create mode 100644 include/crypto/internal/rsa.h
create mode 100644 include/crypto/pkcs7.h
create mode 100644 include/crypto/public_key.h
create mode 100644 include/keys/asymmetric-type.h
create mode 100644 include/linux/asn1.h
create mode 100644 include/linux/asn1_ber_bytecode.h
create mode 100644 include/linux/asn1_decoder.h
create mode 100644 include/linux/oid_registry.h
create mode 100644 lib/asn1_decoder.c
create mode 100644 lib/crypto/Kconfig
create mode 100644 lib/crypto/Makefile
create mode 100644 lib/crypto/asymmetric_type.c
create mode 100644 lib/crypto/pkcs7.asn1
create mode 100644 lib/crypto/pkcs7_parser.c
create mode 100644 lib/crypto/pkcs7_parser.h
create mode 100644 lib/crypto/public_key.c
create mode 100644 lib/crypto/rsa_helper.c
create mode 100644 lib/crypto/rsapubkey.asn1
create mode 100644 lib/crypto/x509.asn1
create mode 100644 lib/crypto/x509_akid.asn1
create mode 100644 lib/crypto/x509_cert_parser.c
create mode 100644 lib/crypto/x509_parser.h
create mode 100644 lib/crypto/x509_public_key.c
rename {drivers/rtc => lib}/date.c (81%)
create mode 100644 lib/oid_registry.c
create mode 100755 scripts/build_OID_registry
create mode 100644 test/lib/asn1.c
create mode 100644 tools/asn1_compiler.cSignature · 1 line
2.21.0
PATCH v3 1/16 linux_compat: move kmemdup() from ubifs.c to linux_compat.c
linux_compat.c is the best place for kmemdup(), which is currenly used only in ubifs.c, but will also be used when other kernel files (in my case, lib/crypto/x509_cert_parser.c and pkcs7_parser.c) will be imported. So just move it.
--- fs/ubifs/ubifs.c | 19 +------------------ lib/linux_compat.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-)
fs/ubifs/ubifs.c +1 -18
@@ -18,6 +18,7 @@#include "ubifs.h" #include <u-boot/zlib.h> +#include <linux/compat.h> #include <linux/err.h> #include <linux/lzo.h>
@@ -70,24 +71,6 @@ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; #ifdef __UBOOT__ -/* from mm/util.c */ - -/** - * kmemdup - duplicate region of memory - * - * @src: memory region to duplicate - * @len: memory region length - * @gfp: GFP mask to use - */ -void *kmemdup(const void *src, size_t len, gfp_t gfp) -{ - void *p; - - p = kmalloc(len, gfp); - if (p) - memcpy(p, src, len); - return p; -} struct crypto_comp { int compressor;
lib/linux_compat.c +19 -0
@@ -40,3 +40,22 @@ void *kmem_cache_alloc(struct kmem_cache *obj, int flag) {return malloc_cache_aligned (obj->sz); } + +/** +* kmemdup - duplicate region of memory +* +* @src: memory region to duplicate +* @len: memory region length +* @gfp: GFP mask to use +* +* Return: newly allocated copy of @src or %NULL in case of error +*/ +void *kmemdup (const void *src,size_t len,gfp_t gfp) +{ +void *p; + + p =kmalloc (len, gfp); +if (p) +memcpy (p, src, len); +return p; +}
Signature · 1 line
2.21.0
PATCH v3 1/16 linux_compat: move kmemdup() from ubifs.c to linux_compat.c
Quoted 6 lines · AKASHI Takahiro
linux_compat.cis the best place forkmemdup(), which is currenly used only inubifs.c, but will also be used when other kernel files (in my case,lib/crypto/x509_cert_parser.candpkcs7_parser.c) will be imported. So just move it.Signed-off-by AKASHI Takahiro<[email protected]>
km_kirkwood_defconfig with CONFIG_UBIFS=y compiles.
PATCH v3 1/16 linux_compat: move kmemdup() from ubifs.c to linux_compat.c
In reply to AKASHI TakahiroQuoted 7 lines · AKASHI Takahiro
linux_compat.cis the best place forkmemdup(), which is currenly used only inubifs.c, but will also be used when other kernel files (in my case,lib/crypto/x509_cert_parser.candpkcs7_parser.c) will be imported. So just move it.Signed-off-by AKASHI Takahiro <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/1a4028d9/attachment.sig>
PATCH v3 2/16 rtc.h: add struct udevice declaration
In reply to AKASHI TakahiroWithout this change, including rtc.h solely will cause a build error.
--- include/rtc.h | 2 ++ 1 file changed, 2 insertions(+)
include/rtc.h +2 -0
@@ -18,6 +18,8 @@#ifdef CONFIG_DM_RTC +struct udevice ; + struct rtc_ops {/** * get() - get the current time
Signature · 1 line
2.21.0
PATCH v3 2/16 rtc.h: add struct udevice declaration
Quoted 3 lines · AKASHI Takahiro
Without this change, including
rtc.hsolely will cause a build error.Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/fac9b8ad/attachment.sig>
PATCH v3 3/16 rtc: move date.c from drivers/rtc/ to lib/
In reply to AKASHI TakahiroIn the next commit, rtc_mktime(), for compatibility with linux, will be implemented using rtc_mktime(), which is no longer drivers/rtc specific. So move this file under lib/.
---
cmd/Kconfig | 1 +
drivers/rtc/Kconfig | 1 +
drivers/rtc/Makefile | 1 -
lib/Kconfig | 3 +++
lib/Makefile | 2 ++
{drivers/rtc => lib}/date.c | 5 ++---
6 files changed, 9 insertions(+), 4 deletions(-)
rename {drivers/rtc => lib}/date.c (96%)cmd/Kconfig +1 -0
@@ -1620,6 +1620,7 @@ config CMD_LED config CMD_DATE bool "date" default y if DM_RTC + select LIB_DATE help Enable the 'date' command for getting/setting the time/date in RTC devices.
drivers/rtc/Kconfig +1 -0
@@ -7,6 +7,7 @@ menu "Real Time Clock" config DM_RTC bool "Enable Driver Model for RTC drivers" depends on DM + select LIB_DATE help Enable drver model for real-time-clock drivers. The RTC uclass then provides the rtc_get()/rtc_set() interface, delegating to
drivers/rtc/Makefile +0 -1
@@ -7,7 +7,6 @@ obj-$(CONFIG_$(SPL_TPL_)DM_RTC) += rtc-uclass.o obj-$(CONFIG_RTC_AT91SAM9_RTT) += at91sam9_rtt.o -obj-y += date.o obj-y += rtc-lib.o obj-$(CONFIG_RTC_DAVINCI) += davinci.o obj-$(CONFIG_RTC_DS1302) += ds1302.o
lib/Kconfig +3 -0
@@ -574,4 +574,7 @@ config TEST_FDTDEC bool "enable fdtdec test" depends on OF_LIBFDT +config LIB_DATE + bool + endmenu
lib/Makefile +2 -0
@@ -117,4 +117,6 @@ else obj-y += vsprintf.o strto.o strmhz.o endif +obj-y += date.o + subdir-ccflags-$(CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED) += -O2
lib/date.c renamed from drivers/rtc/date.c +2 -3
@@ -9,8 +9,7 @@#include <errno.h> #include <rtc.h> -#if defined(CONFIG_CMD_DATE ) || defined(CONFIG_DM_RTC ) || \ - defined(CONFIG_TIMESTAMP ) +#if defined(CONFIG_LIB_DATE ) || defined(CONFIG_TIMESTAMP )#define FEBRUARY 2#define STARTOFTIME 1970
@@ -97,4 +96,4 @@ unsigned long rtc_mktime(const struct rtc_time *tm) return (hours * 60 + tm->tm_min) * 60 + tm->tm_sec; } -#endif +#endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */
Signature · 1 line
2.21.0
PATCH v3 3/16 rtc: move date.c from drivers/rtc/ to lib/
Quoted 5 lines · AKASHI Takahiro
In the next commit,
rtc_mktime(), for compatibility with linux, will be implemented usingrtc_mktime(), which is no longerdrivers/rtcspecific. So move this file underlib/.Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/2b145c3f/attachment.sig>
PATCH v3 4/16 lib: add mktime64() for linux compatibility
In reply to AKASHI TakahiroThis function will be used in lib/crypto/x509_cert_parser.c, which will also be imported from linux code in a later commit.
--- include/linux/time.h | 10 ++++++++++ lib/date.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/linux/time.h +10 -0
@@ -1,6 +1,7 @@#ifndef _LINUX_TIME_H#define _LINUX_TIME_H +#include <rtc.h> #include <linux/types.h> #define _DEFUN (a,b,c) a(c)
@@ -150,4 +151,13 @@ _DEFUN (ctime_r, (tim_p, result), return asctime_r (localtime_r (tim_p, &tm), result); } +/* for compatibility with linux code */ +typedef __s64 time64_t ; + +#ifdef CONFIG_LIB_DATE +time64_t mktime64 (const unsigned int year,const unsigned int mon, +const unsigned int day,const unsigned int hour, +const unsigned int min,const unsigned int sec); +#endif +#endif
lib/date.c +20 -0
@@ -8,6 +8,7 @@#include <command.h> #include <errno.h> #include <rtc.h> +#include <linux/time.h> #if defined(CONFIG_LIB_DATE ) || defined(CONFIG_TIMESTAMP )
@@ -97,3 +98,22 @@ unsigned long rtc_mktime(const struct rtc_time *tm) }#endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */ + +#ifdef CONFIG_LIB_DATE +/* for compatibility with linux code */ +time64_t mktime64 (const unsigned int year,const unsigned int mon, +const unsigned int day,const unsigned int hour, +const unsigned int min,const unsigned int sec) +{ +struct rtc_time time; + + time.tm_year = year; + time.tm_mon = mon; + time.tm_mday = day; + time.tm_hour = hour; + time.tm_min = min; + time.tm_sec = sec; + +return (time64_t )rtc_mktime ((const struct rtc_time *)&time); +} +#endif
Signature · 1 line
2.21.0
PATCH v3 4/16 lib: add mktime64() for linux compatibility
Quoted 4 lines · AKASHI Takahiro
This function will be used in
lib/crypto/x509_cert_parser.c, which will also be imported from linux code in a later commit.Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/e07ebe58/attachment.sig>
PATCH v3 5/16 include: kernel.h: include printk.h
In reply to AKASHI TakahiroAdding "printk.h" will help improve portability from linux kernel code (in my case, lib/asn1_decoder.c and others) where printf and pr_* variant functions are used.
--- include/linux/kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kernel.h +1 -1
@@ -1,8 +1,8 @@#ifndef _LINUX_KERNEL_H#define _LINUX_KERNEL_H -#include <linux/types.h> +#include <linux/printk.h> /* for printf/pr_* utilities */ #define USHRT_MAX ((u16)(~0U))#define SHRT_MAX ((s16)(USHRT_MAX>>1))
Signature · 1 line
2.21.0
PATCH v3 5/16 include: kernel.h: include printk.h
Quoted 2 lines · AKASHI Takahiro
Adding "
printk.h" will help improve portability from linux kernel code (in my case,lib/asn1_decoder.cand others) where printf and
nits:
%s/printf/printk/g
You anyway change the includes in lib/crypto/public_key.c in patch 12/16 and lib/asn1_decoder in patch 09/16. So why not add linux/printk.h there?
Otherwise I would expect this patch to remove #include <linux/printk.h> in all files where it becomes obsolete due to this patch, e.g.
board/synopsys/hsdk/hsdk.carch/arm/mach-uniphier/fdt-fixup.carch/arm/mach-uniphier/dram_init.carch/arm/mach-uniphier/arm32/psci.carch/arm/mach-uniphier/dram/ddrphy-training.c
Best regards
Heinrich
Quoted 22 lines
pr_* variant functions are used.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kernel.h +1
-1@@ -1,8 +1,8 @@#ifndef _LINUX_KERNEL_H#define _LINUX_KERNEL_H -#include <linux/types.h> +#include <linux/printk.h> /* for printf/pr_* utilities */ #define USHRT_MAX ((u16)(~0U))#define SHRT_MAX ((s16)(USHRT_MAX>>1))
PATCH v3 5/16 include: kernel.h: include printk.h
Heinrich,
Quoted 7 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
Adding "
printk.h" will help improve portability from linux kernel code (in my case,lib/asn1_decoder.cand others) where printf andnits:
%s/printf/printk/g
Okay.
Quoted 2 lines
You anyway change the includes in
lib/crypto/public_key.cin patch 12/16 andlib/asn1_decoderin patch 09/16. So why not addlinux/printk.hthere?
I would rather disagree here as I have good reasons.
First, adding "printk.h" to "linux/kernel.h" makes sense simply as Linux's original "linux/kernel.h" also has it. So when you will import any files from linux in the future, you will probably get *less* bothered with missing include files in .c file.
Second, I would like to change linux code at the very minimum if possible. In lib/crypto/public_key.c, for example, I simply deleted not-used and non-existing include files or just replaced any with its counterpart in U-Boot (module.h -> compat.h).
Quoted 8 lines
Otherwise I would expect this patch to remove #include <
linux/printk.h> in all files where it becomes obsolete due to this patch, e.g.
board/synopsys/hsdk/hsdk.carch/arm/mach-uniphier/fdt-fixup.carch/arm/mach-uniphier/dram_init.carch/arm/mach-uniphier/arm32/psci.carch/arm/mach-uniphier/dram/ddrphy-training.c
I don't fully understand that why those files include "linux/kernel.h". Different source files may include "linux/kernel.h" for different reasons. Take board/synopsys/hsdk/hsdk.c, for example.
It uses ARRAY_SIZE macro for its convenience, *not* for printk. I believe that including any include files *directly & explicitly* for its own use of any definitions or functions is a good practice even if such include files may be included *indirectly* via another include file.
So I want to keep this patch unchanged.
-Takahiro Akashi
Quoted 27 lines
Best regards
Heinrich
Quoted 22 lines
pr_* variant functions are used.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/kernel.h +1
-1@@ -1,8 +1,8 @@#ifndef _LINUX_KERNEL_H#define _LINUX_KERNEL_H -#include <linux/types.h> +#include <linux/printk.h> /* for printf/pr_* utilities */ #define USHRT_MAX ((u16)(~0U))#define SHRT_MAX ((s16)(USHRT_MAX>>1))
PATCH v3 5/16 include: kernel.h: include printk.h
In reply to AKASHI TakahiroQuoted 5 lines · AKASHI Takahiro
Adding "
printk.h" will help improve portability from linux kernel code (in my case,lib/asn1_decoder.cand others) where printf and pr_* variant functions are used.Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/95bb7798/attachment.sig>
PATCH v3 5/16 include: kernel.h: include printk.h
Quoted 9 lines · Tom Rini
Quoted 5 lines · AKASHI Takahiro
Adding "
printk.h" will help improve portability from linux kernel code (in my case,lib/asn1_decoder.cand others) where printf and pr_* variant functions are used.Signed-off-by AKASHI Takahiro <[email protected]>Applied to u-boot/master, thanks!
Thank you for the merge.
Heinrich pointed out a typo in the commit message (not in the code):
%s/printf/printk/g
Please correct it if you have a chance.
Thanks,
-Takahiro Akashi
Quoted 2 lines
Signature · 1 line
Tom
PATCH v3 6/16 linux/time.h: include vsprintf.h
In reply to AKASHI TakahiroWithout this commit, time.h possibly causes a build error as asctime_r() uses sprintf().
--- include/linux/time.h | 1 + 1 file changed, 1 insertion(+)
include/linux/time.h +1 -0
@@ -2,6 +2,7 @@#define _LINUX_TIME_H#include <rtc.h> +#include <vsprintf.h> #include <linux/types.h> #define _DEFUN (a,b,c) a(c)
Signature · 1 line
2.21.0
PATCH v3 6/16 linux/time.h: include vsprintf.h
Quoted 2 lines · AKASHI Takahiro
Without this commit,
time.hpossibly causes a build error asasctime_r()usessprintf().
asctime_r() is not a Linux symbol (as of next-20191119)
ctime_r() and asctime_r() are defined as inline functions. ctime_r() is used in multiple places and so we may end up duplicating code. So I would prefer the inline functions in time.h to be moved to a separate C file in lib/.
Best regards
Heinrich
Quoted 19 lines
Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/time.h | 1 + 1 file changed, 1 insertion(+)include/linux/time.h +1
-0@@ -2,6 +2,7 @@#define _LINUX_TIME_H#include <rtc.h> +#include <vsprintf.h> #include <linux/types.h> #define _DEFUN (a,b,c) a(c)
PATCH v3 6/16 linux/time.h: include vsprintf.h
Quoted 6 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
Without this commit,
time.hpossibly causes a build error asasctime_r()usessprintf().
asctime_r()is not a Linux symbol (as of next-20191119)
Quoted 8 lines
ctime_r()andasctime_r()are defined as inline functions.ctime_r()is used in multiple places and so we may end up duplicating code. So I would prefer the inline functions intime.hto be moved to a separate C file inlib/.Best regards
Heinrich
Could it be that in one of your C files you simply didn't follow the U-Boot coding style convention to include common.h first and we don't need this patch at all?
https://www.denx.de/wiki/U-Boot/CodingStyle#Include_files
Best regards
Heinrich
PATCH v3 6/16 linux/time.h: include vsprintf.h
Heinrich,
Quoted 6 lines · Heinrich Schuchardt
Quoted 5 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
Without this commit,
time.hpossibly causes a build error asasctime_r()usessprintf().
asctime_r()is not a Linux symbol (as of next-20191119)
I simply don't get your point here.
Quoted 5 lines
Quoted 5 lines
ctime_r()andasctime_r()are defined as inline functions.ctime_r()is used in multiple places and so we may end up duplicating code. So I would prefer the inline functions intime.hto be moved to a separate C file inlib/.
Basically I'm reluctant to do so.
I have never touched ctime_r() nor asctime_r() as they were introduced by Wolfgang in 2002. Since then, nobody complained. So why now?
Quoted 6 lines
Quoted 3 lines
Best regards
Heinrich
Could it be that in one of your C files you simply didn't follow the U-Boot coding style convention to include
common.hfirst
I will address this issue in general in the future.
Quoted 2 lines
and we don't
need this patch at all?
I commented against this above.
I believe that *hidden* dependency of include files should not be exposed to users. In this case, for example, any code that uses asctime_r() should not be bothered with such a dependency as the code doesn't know what functions asctime_r() internally uses or even if that function is inline or not.
I also mentioned this in another thread in different words:
https://lists.denx.de/pipermail/u-boot/2019-November/391959.html
Thanks,
-Takahiro Akashi
Quoted 5 lines
https://www.denx.de/wiki/U-Boot/CodingStyle#Include_files
Best regards
Heinrich
PATCH v3 6/16 linux/time.h: include vsprintf.h
In reply to AKASHI TakahiroQuoted 4 lines · AKASHI Takahiro
Without this commit,
time.hpossibly causes a build error asasctime_r()usessprintf().Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/a449f23e/attachment.sig>
PATCH v3 7/16 cmd: add asn1_compiler
In reply to AKASHI TakahiroImported from linux kernel v5.3:
asn1.h without changes
asn1_ber_bytecode.h without changes
asn1_decoder.h without changes
asn1_compiler.c without changes
This host command will be used to create a ASN1 parser, for example, for pkcs7 messages or x509 certificates. More specifically, it will generate *byte code* which will be interpreted by asn1 decoder library.
--- include/linux/asn1.h | 65 ++ include/linux/asn1_ber_bytecode.h | 89 ++ include/linux/asn1_decoder.h | 20 + lib/Kconfig | 3 + scripts/Makefile.build | 4 +- tools/Makefile | 3 + tools/asn1_compiler.c | 1611 +++++++++++++++++++++++++++++ 7 files changed, 1793 insertions(+), 2 deletions(-) create mode 100644 include/linux/asn1.h create mode 100644 include/linux/asn1_ber_bytecode.h create mode 100644 include/linux/asn1_decoder.h create mode 100644 tools/asn1_compiler.c
include/linux/asn1.h new file +65 -0
@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* ASN.1 BER/DER/CER encoding definitions +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells (dhowells at redhat.com) +*/ + +#ifndef _LINUX_ASN1_H +#define _LINUX_ASN1_H + +/* Class */ +enum asn1_class { +ASN1_UNIV =0 ,/* Universal */ +ASN1_APPL =1 ,/* Application */ +ASN1_CONT =2 ,/* Context */ +ASN1_PRIV =3 /* Private */ +}; +#define ASN1_CLASS_BITS 0xc0 + + +enum asn1_method { +ASN1_PRIM =0 ,/* Primitive */ +ASN1_CONS =1 /* Constructed */ +}; +#define ASN1_CONS_BIT 0x20 + +/* Tag */ +enum asn1_tag { +ASN1_EOC =0 ,/* End Of Contents or N/A */ +ASN1_BOOL =1 ,/* Boolean */ +ASN1_INT =2 ,/* Integer */ +ASN1_BTS =3 ,/* Bit String */ +ASN1_OTS =4 ,/* Octet String */ +ASN1_NULL =5 ,/* Null */ +ASN1_OID =6 ,/* Object Identifier */ +ASN1_ODE =7 ,/* Object Description */ +ASN1_EXT =8 ,/* External */ +ASN1_REAL =9 ,/* Real float */ +ASN1_ENUM =10 ,/* Enumerated */ +ASN1_EPDV =11 ,/* Embedded PDV */ +ASN1_UTF8STR =12 ,/* UTF8 String */ +ASN1_RELOID =13 ,/* Relative OID */ +/* 14 - Reserved */ +/* 15 - Reserved */ +ASN1_SEQ =16 ,/* Sequence and Sequence of */ +ASN1_SET =17 ,/* Set and Set of */ +ASN1_NUMSTR =18 ,/* Numerical String */ +ASN1_PRNSTR =19 ,/* Printable String */ +ASN1_TEXSTR =20 ,/* T61 String / Teletext String */ +ASN1_VIDSTR =21 ,/* Videotex String */ +ASN1_IA5STR =22 ,/* IA5 String */ +ASN1_UNITIM =23 ,/* Universal Time */ +ASN1_GENTIM =24 ,/* General Time */ +ASN1_GRASTR =25 ,/* Graphic String */ +ASN1_VISSTR =26 ,/* Visible String */ +ASN1_GENSTR =27 ,/* General String */ +ASN1_UNISTR =28 ,/* Universal String */ +ASN1_CHRSTR =29 ,/* Character String */ +ASN1_BMPSTR =30 ,/* BMP String */ +ASN1_LONG_TAG =31 /* Long form tag */ +}; + +#define ASN1_INDEFINITE_LENGTH 0x80 + +#endif /* _LINUX_ASN1_H */
include/linux/asn1_ber_bytecode.h new file +89 -0
89 lines not on this page · raw message
include/linux/asn1_decoder.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* ASN.1 decoder +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#ifndef _LINUX_ASN1_DECODER_H +#define _LINUX_ASN1_DECODER_H + +#include <linux/asn1.h> + +struct asn1_decoder ; + +extern int asn1_ber_decoder (const struct asn1_decoder *decoder, +void *context, +const unsigned char *data, +size_t datalen); + +#endif /* _LINUX_ASN1_DECODER_H */
lib/Kconfig +3 -0
@@ -566,6 +566,9 @@ config SMBIOS_PRODUCT_NAME endmenu +config ASN1_COMPILER + bool + source lib/efi/Kconfig source lib/efi_loader/Kconfig source lib/optee/Kconfig
scripts/Makefile.build +2 -2
@@ -328,10 +328,10 @@ $(obj)/%.lds: $(src)/%.lds.S FORCE # ASN.1 grammar # --------------------------------------------------------------------------- quiet_cmd_asn1_compiler = ASN.1 $@ - cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ + cmd_asn1_compiler = $(objtree)/tools/asn1_compiler $< \ $(subst .h,.c,$@) $(subst .c,.h,$@) -$(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler +$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/tools/asn1_compiler $(call cmd,asn1_compiler) # Build the compiled-in targets
tools/Makefile +3 -0
@@ -207,6 +207,9 @@ endif hostprogs-$(CONFIG_MIPS) += mips-relocs +hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler +HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.
tools/asn1_compiler.c new file +1611 -0
1,611 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 7/16 cmd: add asn1_compiler
Quoted 6 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
asn1.hwithout changes
asn1_ber_bytecode.hwithout changes
asn1_decoder.hwithout changes
asn1_compiler.cwithout changes
Quoted 6 lines
This host command will be used to create a ASN1 parser, for example, for pkcs7 messages or x509 certificates. More specifically, it will generate *byte code* which will be interpreted by asn1 decoder library.
Signed-off-by AKASHI Takahiro <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/dbe45412/attachment.sig>
PATCH v3 8/16 Makefile: add build script for asn1 parsers
In reply to AKASHI TakahiroThis rule will be used to build x509 and pkcs7 parsers.
--- Makefile | 1 + scripts/Makefile.build | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
Makefile +1 -0
@@ -1921,6 +1921,7 @@ clean: $(clean-dirs) -o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \ + -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \
scripts/Makefile.build +3 -1
@@ -419,9 +419,11 @@ targets += $(multi-used-y) $(multi-used-m) intermediate_targets = $(foreach sfx, $(2), \ $(patsubst %$(strip $(1)),%$(sfx), \ $(filter %$(strip $(1)), $(targets)))) +# %.asn1.o <- %.asn1.[ch] <- %.asn1 # %.lex.o <- %.lex.c <- %.l # %.tab.o <- %.tab.[ch] <- %.y -targets += $(call intermediate_targets, .lex.o, .lex.c) \ +targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ + $(call intermediate_targets, .lex.o, .lex.c) \ $(call intermediate_targets, .tab.o, .tab.c .tab.h) # Descending
Signature · 1 line
2.21.0
PATCH v3 8/16 Makefile: add build script for asn1 parsers
Quoted 3 lines · AKASHI Takahiro
This rule will be used to build x509 and pkcs7 parsers.
Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/a47a7327/attachment.sig>
PATCH v3 9/16 lib: add asn1 decoder
In reply to AKASHI TakahiroImported from linux kernel v5.3:
lib/asn1_decoder.c with changes marked as __UBOOT__
--- lib/Kconfig | 5 + lib/Makefile | 1 + lib/asn1_decoder.c | 527 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 lib/asn1_decoder.c
lib/Kconfig +5 -0
@@ -569,6 +569,11 @@ endmenu config ASN1_COMPILER bool +config ASN1_DECODER + bool + help + Enable asn1 decoder library. + source lib/efi/Kconfig source lib/efi_loader/Kconfig source lib/optee/Kconfig
lib/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_OF_LIVE) += of_live.o obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE) += optee/ +obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o obj-$(CONFIG_AES) += aes.o
lib/asn1_decoder.c new file +527 -0
527 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 9/16 lib: add asn1 decoder
Quoted 4 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
lib/asn1_decoder.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/c42aede6/attachment.sig>
PATCH v3 10/16 doc: add README for asn1 compiler and decoder
In reply to AKASHI TakahiroThis document gives a brief description about ASN1 compiler as well as ASN1 decoder.
--- doc/README.asn1 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 doc/README.asn1
doc/README.asn1 new file +40 -0
@@ -0,0 +1,40 @@ +ASN1 +==== + +Abstract Syntax Notation One (or ASN1) is a standard by ITU-T and ISO/IEC +and used as a description language for defining data structure in +an independent manner. +Any data described in ASN1 notation can be serialized (or encoded) and +de-serialized (or decoded) with well-defined encoding rules. + +A combination of ASN1 compiler and ASN1 decoder library function will +provide a function interface for parsing encoded binary into specific +data structure: +1) define data structure in a text file (*.asn1) +2) define "action" routines for specific "tags" defined in (1) +3) generate bytecode as a C file (*.asn1.[ch]) from *.asn1 file + with ASN1 compiler (tools/asn1_compiler) +4) call a ASN1 decoder (asn1_ber_decoder()) with bytecode and data + +Usage of ASN1 compiler +---------------------- + asn1_compiler [-v] [-d] <grammar-file> <c-file> <hdr-file> + + <grammar-file>: ASN1 input file + <c-file>: generated C file + <hdr-file>: generated include file + +Usage of ASN1 decoder +--------------------- + int asn1_ber_decoder(const struct asn1_decoder *decoder, void *context, + const unsigned char *data, size_t datalen); + + @decoder: bytecode binary + @context: context for decoder + @data: data to be parsed + @datalen: size of data + + +As of writing this, ASN1 compiler and decoder are used to implement +X509 certificate parser, pcks7 message parser and RSA public key parser +for UEFI secure boot.
Signature · 1 line
2.21.0
PATCH v3 10/16 doc: add README for asn1 compiler and decoder
Quoted 4 lines · AKASHI Takahiro
This document gives a brief description about ASN1 compiler as well as ASN1 decoder.
Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/6fb1a680/attachment.sig>
PATCH v3 11/16 lib: add oid registry utility
In reply to AKASHI TakahiroImported from linux kernel v5.3:
build_OID_registry without changes
oid_registry.h without changes
oid_registry.c with changes marked as __UBOOT__
--- include/linux/oid_registry.h | 117 ++++++++++++++++++++ lib/Kconfig | 5 + lib/Makefile | 16 +++ lib/oid_registry.c | 179 ++++++++++++++++++++++++++++++ scripts/build_OID_registry | 203 +++++++++++++++++++++++++++++++++++ 5 files changed, 520 insertions(+) create mode 100644 include/linux/oid_registry.h create mode 100644 lib/oid_registry.c create mode 100755 scripts/build_OID_registry
include/linux/oid_registry.h new file +117 -0
@@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* ASN.1 Object identifier (OID) registry +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells (dhowells at redhat.com) +*/ + +#ifndef _LINUX_OID_REGISTRY_H +#define _LINUX_OID_REGISTRY_H + +#include <linux/types.h> + +/* +* OIDs are turned into these values if possible, or OID__NR if not held here. +* +* NOTE! Do not mess with the format of each line as this is read by +* build_OID_registry.pl to generate the data for look_up_OID(). +*/ +enum OID { + OID_id_dsa_with_sha1,/* 1.2.840.10030.4.3 */ + OID_id_dsa,/* 1.2.840.10040.4.1 */ + OID_id_ecdsa_with_sha1,/* 1.2.840.10045.4.1 */ + OID_id_ecPublicKey,/* 1.2.840.10045.2.1 */ + +/* PKCS#1 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)} */ + OID_rsaEncryption,/* 1.2.840.113549.1.1.1 */ + OID_md2WithRSAEncryption,/* 1.2.840.113549.1.1.2 */ + OID_md3WithRSAEncryption,/* 1.2.840.113549.1.1.3 */ + OID_md4WithRSAEncryption,/* 1.2.840.113549.1.1.4 */ + OID_sha1WithRSAEncryption,/* 1.2.840.113549.1.1.5 */ + OID_sha256WithRSAEncryption,/* 1.2.840.113549.1.1.11 */ + OID_sha384WithRSAEncryption,/* 1.2.840.113549.1.1.12 */ + OID_sha512WithRSAEncryption,/* 1.2.840.113549.1.1.13 */ + OID_sha224WithRSAEncryption,/* 1.2.840.113549.1.1.14 */ +/* PKCS#7 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-7(7)} */ + OID_data,/* 1.2.840.113549.1.7.1 */ + OID_signed_data,/* 1.2.840.113549.1.7.2 */ +/* PKCS#9 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-9(9)} */ + OID_email_address,/* 1.2.840.113549.1.9.1 */ + OID_contentType,/* 1.2.840.113549.1.9.3 */ + OID_messageDigest,/* 1.2.840.113549.1.9.4 */ + OID_signingTime,/* 1.2.840.113549.1.9.5 */ + OID_smimeCapabilites,/* 1.2.840.113549.1.9.15 */ + OID_smimeAuthenticatedAttrs,/* 1.2.840.113549.1.9.16.2.11 */ + +/* {iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2)} */ + OID_md2,/* 1.2.840.113549.2.2 */ + OID_md4,/* 1.2.840.113549.2.4 */ + OID_md5,/* 1.2.840.113549.2.5 */ + +/* Microsoft Authenticode & Software Publishing */ + OID_msIndirectData,/* 1.3.6.1.4.1.311.2.1.4 */ + OID_msStatementType,/* 1.3.6.1.4.1.311.2.1.11 */ + OID_msSpOpusInfo,/* 1.3.6.1.4.1.311.2.1.12 */ + OID_msPeImageDataObjId,/* 1.3.6.1.4.1.311.2.1.15 */ + OID_msIndividualSPKeyPurpose,/* 1.3.6.1.4.1.311.2.1.21 */ + OID_msOutlookExpress,/* 1.3.6.1.4.1.311.16.4 */ + + OID_certAuthInfoAccess,/* 1.3.6.1.5.5.7.1.1 */ + OID_sha1,/* 1.3.14.3.2.26 */ + OID_sha256,/* 2.16.840.1.101.3.4.2.1 */ + OID_sha384,/* 2.16.840.1.101.3.4.2.2 */ + OID_sha512,/* 2.16.840.1.101.3.4.2.3 */ + OID_sha224,/* 2.16.840.1.101.3.4.2.4 */ + +/* Distinguished Name attribute IDs [RFC 2256] */ + OID_commonName,/* 2.5.4.3 */ + OID_surname,/* 2.5.4.4 */ + OID_countryName,/* 2.5.4.6 */ + OID_locality,/* 2.5.4.7 */ + OID_stateOrProvinceName,/* 2.5.4.8 */ + OID_organizationName,/* 2.5.4.10 */ + OID_organizationUnitName,/* 2.5.4.11 */ + OID_title,/* 2.5.4.12 */ + OID_description,/* 2.5.4.13 */ + OID_name,/* 2.5.4.41 */ + OID_givenName,/* 2.5.4.42 */ + OID_initials,/* 2.5.4.43 */ + OID_generationalQualifier,/* 2.5.4.44 */ + +/* Certificate extension IDs */ + OID_subjectKeyIdentifier,/* 2.5.29.14 */ + OID_keyUsage,/* 2.5.29.15 */ + OID_subjectAltName,/* 2.5.29.17 */ + OID_issuerAltName,/* 2.5.29.18 */ + OID_basicConstraints,/* 2.5.29.19 */ + OID_crlDistributionPoints,/* 2.5.29.31 */ + OID_certPolicies,/* 2.5.29.32 */ + OID_authorityKeyIdentifier,/* 2.5.29.35 */ + OID_extKeyUsage,/* 2.5.29.37 */ + +/* EC-RDSA */ + OID_gostCPSignA,/* 1.2.643.2.2.35.1 */ + OID_gostCPSignB,/* 1.2.643.2.2.35.2 */ + OID_gostCPSignC,/* 1.2.643.2.2.35.3 */ + OID_gost2012PKey256,/* 1.2.643.7.1.1.1.1 */ + OID_gost2012PKey512,/* 1.2.643.7.1.1.1.2 */ + OID_gost2012Digest256,/* 1.2.643.7.1.1.2.2 */ + OID_gost2012Digest512,/* 1.2.643.7.1.1.2.3 */ + OID_gost2012Signature256,/* 1.2.643.7.1.1.3.2 */ + OID_gost2012Signature512,/* 1.2.643.7.1.1.3.3 */ + OID_gostTC26Sign256A,/* 1.2.643.7.1.2.1.1.1 */ + OID_gostTC26Sign256B,/* 1.2.643.7.1.2.1.1.2 */ + OID_gostTC26Sign256C,/* 1.2.643.7.1.2.1.1.3 */ + OID_gostTC26Sign256D,/* 1.2.643.7.1.2.1.1.4 */ + OID_gostTC26Sign512A,/* 1.2.643.7.1.2.1.2.1 */ + OID_gostTC26Sign512B,/* 1.2.643.7.1.2.1.2.2 */ + OID_gostTC26Sign512C,/* 1.2.643.7.1.2.1.2.3 */ + +OID__NR +}; + +extern enum OID look_up_OID (const void *data,size_t datasize); +extern int sprint_oid (const void *,size_t ,char *,size_t ); +extern int sprint_OID (enum OID ,char *,size_t ); + +#endif /* _LINUX_OID_REGISTRY_H */
lib/Kconfig +5 -0
@@ -574,6 +574,11 @@ config ASN1_DECODER help Enable asn1 decoder library. +config OID_REGISTRY + bool + help + Enable fast lookup object identifier registry. + source lib/efi/Kconfig source lib/efi_loader/Kconfig source lib/optee/Kconfig
lib/Makefile +16 -0
@@ -120,4 +120,20 @@ endif obj-y += date.o +# +# Build a fast OID lookup registry from include/linux/oid_registry.h +# +obj-$(CONFIG_OID_REGISTRY) += oid_registry.o + +$(obj)/oid_registry.o: $(obj)/oid_registry_data.c + +$(obj)/oid_registry_data.c: $(srctree)/include/linux/oid_registry.h \ + $(srctree)/scripts/build_OID_registry + $(call cmd,build_OID_registry) + +quiet_cmd_build_OID_registry = GEN $@ + cmd_build_OID_registry = perl $(srctree)/scripts/build_OID_registry $< $@ + +clean-files += oid_registry_data.c + subdir-ccflags-$(CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED) += -O2
lib/oid_registry.c new file +179 -0
179 lines not on this page · raw message
scripts/build_OID_registry new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 11/16 lib: add oid registry utility
Quoted 6 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
build_OID_registrywithout changes
oid_registry.hwithout changes
oid_registry.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/b354db2d/attachment.sig>
PATCH v3 12/16 lib: crypto: add public key utility
In reply to AKASHI TakahiroImported from linux kernel v5.3:
asymmetric-type.h with changes marked as __UBOOT__ asymmetric_type.c with changes marked as __UBOOT__ public_key.h with changes marked as __UBOOT__ public_key.c with changes marked as __UBOOT__
--- include/crypto/public_key.h | 90 +++++ include/keys/asymmetric-type.h | 88 +++++ lib/crypto/Kconfig | 19 + lib/crypto/Makefile | 10 + lib/crypto/asymmetric_type.c | 668 +++++++++++++++++++++++++++++++++ lib/crypto/public_key.c | 376 +++++++++++++++++++ 6 files changed, 1251 insertions(+) create mode 100644 include/crypto/public_key.h create mode 100644 include/keys/asymmetric-type.h create mode 100644 lib/crypto/Kconfig create mode 100644 lib/crypto/Makefile create mode 100644 lib/crypto/asymmetric_type.c create mode 100644 lib/crypto/public_key.c
include/crypto/public_key.h new file +90 -0
@@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Asymmetric public-key algorithm definitions +* +* See Documentation/crypto/asymmetric-keys.txt +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells (dhowells at redhat.com) +*/ + +#ifndef _LINUX_PUBLIC_KEY_H +#define _LINUX_PUBLIC_KEY_H + +#ifdef __UBOOT__ +#include <linux/types.h> +#else +#include <linux/keyctl.h> +#endif +#include <linux/oid_registry.h> + +/* +* Cryptographic data for the public-key subtype of the asymmetric key type. +* +* Note that this may include private part of the key as well as the public +* part. +*/ +struct public_key { +void *key; +u32 keylen; +enum OID algo; +void *params; +u32 paramlen; +bool key_is_private; +const char *id_type; +const char *pkey_algo; +}; + +extern void public_key_free (struct public_key *key); + +/* +* Public key cryptography signature data +*/ +struct public_key_signature { +struct asymmetric_key_id *auth_ids[2 ]; +u8 *s;/* Signature */ +u32 s_size;/* Number of bytes in signature */ +u8 *digest; +u8 digest_size;/* Number of bytes in digest */ +const char *pkey_algo; +const char *hash_algo; +const char *encoding; +}; + +extern void public_key_signature_free (struct public_key_signature *sig); + +#ifndef __UBOOT__ +extern struct asymmetric_key_subtype public_key_subtype; + +struct key ; +struct key_type ; +union key_payload ; + +extern int restrict_link_by_signature (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trust_keyring); + +extern int restrict_link_by_key_or_keyring (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trusted); + +extern int restrict_link_by_key_or_keyring_chain (struct key *trust_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trusted); + +extern int query_asymmetric_key (const struct kernel_pkey_params *, +struct kernel_pkey_query *); + +extern int encrypt_blob (struct kernel_pkey_params *,const void *,void *); +extern int decrypt_blob (struct kernel_pkey_params *,const void *,void *); +extern int create_signature (struct kernel_pkey_params *,const void *,void *); +extern int verify_signature (const struct key *, +const struct public_key_signature *); + +int public_key_verify_signature (const struct public_key *pkey, +const struct public_key_signature *sig); +#endif /* !__UBOOT__ */ + +#endif /* _LINUX_PUBLIC_KEY_H */
include/keys/asymmetric-type.h new file +88 -0
88 lines not on this page · raw message
lib/crypto/Kconfig new file +19 -0
@@ -0,0 +1,19 @@ +menuconfig ASYMMETRIC_KEY_TYPE + bool "Asymmetric (public-key cryptographic) key Support" + help + This option provides support for a key type that holds the data for + the asymmetric keys used for public key cryptographic operations such + as encryption, decryption, signature generation and signature + verification. + +if ASYMMETRIC_KEY_TYPE + +config ASYMMETRIC_PUBLIC_KEY_SUBTYPE + bool "Asymmetric public-key crypto algorithm subtype" + help + This option provides support for asymmetric public key type handling. + If signature generation and/or verification are to be used, + appropriate hash algorithms (such as SHA-1) must be available. + ENOPKG will be reported if the requisite algorithm is unavailable. + +endif # ASYMMETRIC_KEY_TYPE
lib/crypto/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Makefile for asymmetric cryptographic keys +# + +obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o + +asymmetric_keys-y := asymmetric_type.o + +obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o
lib/crypto/asymmetric_type.c new file +668 -0
668 lines not on this page · raw message
lib/crypto/public_key.c new file +376 -0
376 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 12/16 lib: crypto: add public key utility
Quoted 7 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
asymmetric-type.hwith changes marked as__UBOOT__asymmetric_type.cwith changes marked as__UBOOT__public_key.hwith changes marked as__UBOOT__public_key.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/32d183f1/attachment.sig>
PATCH v3 13/16 lib: crypto: add rsa public key parser
In reply to AKASHI TakahiroImported from linux kernel v5.3:
rsapubkey.asn1 without changesrsa.h without changesrsa_helper.c with changes marked as __UBOOT__
--- include/crypto/internal/rsa.h | 57 ++++++++++ lib/crypto/Kconfig | 11 ++ lib/crypto/Makefile | 11 ++ lib/crypto/rsa_helper.c | 198 ++++++++++++++++++++++++++++++++++ lib/crypto/rsapubkey.asn1 | 4 + 5 files changed, 281 insertions(+) create mode 100644 include/crypto/internal/rsa.h create mode 100644 lib/crypto/rsa_helper.c create mode 100644 lib/crypto/rsapubkey.asn1
include/crypto/internal/rsa.h new file +57 -0
@@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* RSA internal helpers +* +* Copyright (c) 2015, Intel Corporation +* Authors: Tadeusz Struk <[email protected]> +*/ +#ifndef _RSA_HELPER_ +#define _RSA_HELPER_ +#include <linux/types.h> + +/** +* rsa_key - RSA key structure +* @n : RSA modulus raw byte stream +* @e : RSA public exponent raw byte stream +* @d : RSA private exponent raw byte stream +* @p : RSA prime factor p of n raw byte stream +* @q : RSA prime factor q of n raw byte stream +* @dp : RSA exponent d mod (p - 1) raw byte stream +* @dq : RSA exponent d mod (q - 1) raw byte stream +* @qinv : RSA CRT coefficient q^(-1) mod p raw byte stream +* @n_sz : length in bytes of RSA modulus n +* @e_sz : length in bytes of RSA public exponent +* @d_sz : length in bytes of RSA private exponent +* @p_sz : length in bytes of p field +* @q_sz : length in bytes of q field +* @dp_sz : length in bytes of dp field +* @dq_sz : length in bytes of dq field +* @qinv_sz : length in bytes of qinv field +*/ +struct rsa_key { +const u8 *n; +const u8 *e; +const u8 *d; +const u8 *p; +const u8 *q; +const u8 *dp; +const u8 *dq; +const u8 *qinv; +size_t n_sz; +size_t e_sz; +size_t d_sz; +size_t p_sz; +size_t q_sz; +size_t dp_sz; +size_t dq_sz; +size_t qinv_sz; +}; + +int rsa_parse_pub_key (struct rsa_key *rsa_key,const void *key, +unsigned int key_len); + +int rsa_parse_priv_key (struct rsa_key *rsa_key,const void *key, +unsigned int key_len); + +extern struct crypto_template rsa_pkcs1pad_tmpl; +#endif
lib/crypto/Kconfig +11 -0
@@ -16,4 +16,15 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE appropriate hash algorithms (such as SHA-1) must be available. ENOPKG will be reported if the requisite algorithm is unavailable. +config RSA_PUBLIC_KEY_PARSER + bool "RSA public key parser" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select ASN1_DECODER + select ASN1_COMPILER + select OID_REGISTRY + help + This option provides support for parsing a blob containing RSA + public key data and provides the ability to instantiate a public + key. + endif # ASYMMETRIC_KEY_TYPE
lib/crypto/Makefile +11 -0
@@ -8,3 +8,14 @@ obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o asymmetric_keys-y := asymmetric_type.o obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o + +# +# RSA public key parser +# +obj-$(CONFIG_RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o +rsa_public_key-y := \ + rsapubkey.asn1.o \ + rsa_helper.o + +$(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h +$(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h
lib/crypto/rsa_helper.c new file +198 -0
198 lines not on this page · raw message
lib/crypto/rsapubkey.asn1 new file +4 -0
@@ -0,0 +1,4 @@ +RsaPubKey ::= SEQUENCE { + n INTEGER ({ rsa_get_n }), + e INTEGER ({ rsa_get_e }) +}
Signature · 1 line
2.21.0
PATCH v3 13/16 lib: crypto: add rsa public key parser
Quoted 6 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
rsapubkey.asn1 without changesrsa.hwithout changesrsa_helper.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/9ecad4e5/attachment.sig>
PATCH v3 14/16 lib: crypto: add x509 parser
In reply to AKASHI TakahiroImported from linux kernel v5.3:
x509.asn1 without changes
x509_akid.asn1 without changes x509_parser.h without changes x509_cert_parser.c with changes marked as __UBOOT__ x509_public_key.c with changes marked as __UBOOT__
--- lib/Kconfig | 1 + lib/Makefile | 1 + lib/crypto/Kconfig | 12 + lib/crypto/Makefile | 17 + lib/crypto/x509.asn1 | 60 +++ lib/crypto/x509_akid.asn1 | 35 ++ lib/crypto/x509_cert_parser.c | 697 ++++++++++++++++++++++++++++++++++ lib/crypto/x509_parser.h | 57 +++ lib/crypto/x509_public_key.c | 292 ++++++++++++++ 9 files changed, 1172 insertions(+) create mode 100644 lib/crypto/x509.asn1 create mode 100644 lib/crypto/x509_akid.asn1 create mode 100644 lib/crypto/x509_cert_parser.c create mode 100644 lib/crypto/x509_parser.h create mode 100644 lib/crypto/x509_public_key.c
lib/Kconfig +1 -0
@@ -265,6 +265,7 @@ config AES present. source lib/rsa/Kconfig +source lib/crypto/Kconfig config TPM bool "Trusted Platform Module (TPM) Support"
lib/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_CMD_DHRYSTONE) += dhry/ obj-$(CONFIG_ARCH_AT91) += at91/ obj-$(CONFIG_OPTEE) += optee/ obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o +obj-y += crypto/ obj-$(CONFIG_AES) += aes.o
lib/crypto/Kconfig +12 -0
@@ -27,4 +27,16 @@ config RSA_PUBLIC_KEY_PARSER public key data and provides the ability to instantiate a public key. +config X509_CERTIFICATE_PARSER + bool "X.509 certificate parser" + depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select ASN1_DECODER + select ASN1_COMPILER + select OID_REGISTRY + select LIB_DATE + help + This option provides support for parsing X.509 format blobs for key + data and provides the ability to instantiate a crypto key from a + public key packet found inside the certificate. + endif # ASYMMETRIC_KEY_TYPE
lib/crypto/Makefile +17 -0
@@ -19,3 +19,20 @@ rsa_public_key-y := \ $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h $(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h + +# +# X.509 Certificate handling +# +obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o +x509_key_parser-y := \ + x509.asn1.o \ + x509_akid.asn1.o \ + x509_cert_parser.o \ + x509_public_key.o + +$(obj)/x509_cert_parser.o: \ + $(obj)/x509.asn1.h \ + $(obj)/x509_akid.asn1.h + +$(obj)/x509.asn1.o: $(obj)/x509.asn1.c $(obj)/x509.asn1.h +$(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h
lib/crypto/x509.asn1 new file +60 -0
60 lines not on this page · raw message
lib/crypto/x509_akid.asn1 new file +35 -0
@@ -0,0 +1,35 @@ +-- X.509 AuthorityKeyIdentifier +-- rfc5280 section 4.2.1.1 + +AuthorityKeyIdentifier ::= SEQUENCE { + keyIdentifier [0] IMPLICIT KeyIdentifier OPTIONAL, + authorityCertIssuer [1] IMPLICIT GeneralNames OPTIONAL, + authorityCertSerialNumber [2] IMPLICIT CertificateSerialNumber OPTIONAL + } + +KeyIdentifier ::= OCTET STRING ({ x509_akid_note_kid }) + +CertificateSerialNumber ::= INTEGER ({ x509_akid_note_serial }) + +GeneralNames ::= SEQUENCE OF GeneralName + +GeneralName ::= CHOICE { + otherName [0] ANY, + rfc822Name [1] IA5String, + dNSName [2] IA5String, + x400Address [3] ANY, + directoryName [4] Name ({ x509_akid_note_name }), + ediPartyName [5] ANY, + uniformResourceIdentifier [6] IA5String, + iPAddress [7] OCTET STRING, + registeredID [8] OBJECT IDENTIFIER + } + +Name ::= SEQUENCE OF RelativeDistinguishedName + +RelativeDistinguishedName ::= SET OF AttributeValueAssertion + +AttributeValueAssertion ::= SEQUENCE { + attributeType OBJECT IDENTIFIER ({ x509_note_OID }), + attributeValue ANY ({ x509_extract_name_segment }) + }
lib/crypto/x509_cert_parser.c new file +697 -0
697 lines not on this page · raw message
lib/crypto/x509_parser.h new file +57 -0
57 lines not on this page · raw message
lib/crypto/x509_public_key.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 14/16 lib: crypto: add x509 parser
Quoted 8 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
x509.asn1 without changes
x509_akid.asn1 without changesx509_parser.hwithout changesx509_cert_parser.cwith changes marked as__UBOOT__x509_public_key.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/8d050bd2/attachment.sig>
PATCH v3 14/16 lib: crypto: add x509 parser
Quoted 9 lines · Tom Rini
Quoted 7 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
x509.asn1 without changes
x509_akid.asn1 without changesx509_parser.hwithout changesx509_cert_parser.cwith changes marked as__UBOOT__x509_public_key.cwith changes marked as__UBOOT__
Quoted 4 lines
Quoted 1 line
Signed-off-by AKASHI Takahiro <[email protected]>Applied to u-boot/master, thanks!
Hello Tom,
this patch causes a build error for rpi_0_w_defconfig with CONFIG_X509_CERTIFICATE_PARSER=y:
In file included from include/linux/time.h:4,
from lib/crypto/x509_parser.h:8,
from lib/crypto/x509_cert_parser.c:20:
include/rtc.h:197:26: error: unknown type name ‘uchar’; did you mean
‘unchar’?
void rtc_write8(int reg, uchar val);
^~~~~
uncharmake[4]: *** [scripts/Makefile.build:279: lib/crypto/x509_cert_parser.o] Error 1
The error is caused by:
include/linux/types.h:88:typedef unsigned char unchar;
I have prepared a patch but will first run it through Gitlab:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/commit/f574992867cf40f48a381f88c1ac15a47dbe1baf
@Takahiro:
I am wondering why this did not show up in your tests. Did Tom miss a patch?
Best regards
Heinrich
PATCH v3 14/16 lib: crypto: add x509 parser
Quoted 32 lines · Heinrich Schuchardt
Quoted 9 lines · Tom Rini
Quoted 7 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
x509.asn1 without changes
x509_akid.asn1 without changesx509_parser.hwithout changesx509_cert_parser.cwith changes marked as__UBOOT__x509_public_key.cwith changes marked as__UBOOT__Quoted 4 lines
Quoted 1 line
Signed-off-by AKASHI Takahiro <[email protected]>Applied to u-boot/master, thanks!
Hello Tom,
this patch causes a build error for
rpi_0_w_defconfigwithCONFIG_X509_CERTIFICATE_PARSER=y:In file included from
include/linux/time.h:4,from lib/crypto/x509_parser.h:8, from lib/crypto/x509_cert_parser.c:20: include/rtc.h:197:26: error: unknown type name ‘uchar’; did you mean ‘unchar’? void rtc_write8(int reg, uchar val); ^~~~~ uncharmake[4]: *** [
scripts/Makefile.build:279:lib/crypto/x509_cert_parser.o] Error 1The error is caused by:
Quoted 8 lines
include/linux/types.h:88:typedef unsigned char unchar;
I have prepared a patch but will first run it through Gitlab:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/commit/f574992867cf40f48a381f88c1ac15a47dbe1baf
@Takahiro:
I am wondering why this did not show up in your tests. Did Tom miss a patch?
Only sandbox enables any of this out of the box, which is why I've taken it at this point in the window. It's otherwise neutral and as good as it was going to get prior to inclusion somewhere for wider testing. Which, thanks for doing.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191207/9a8cc0cf/attachment.sig>
PATCH v3 14/16 lib: crypto: add x509 parser
Quoted 33 lines · Tom Rini
Quoted 32 lines · Heinrich Schuchardt
Quoted 9 lines · Tom Rini
Quoted 7 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
x509.asn1 without changes
x509_akid.asn1 without changesx509_parser.hwithout changesx509_cert_parser.cwith changes marked as__UBOOT__x509_public_key.cwith changes marked as__UBOOT__Quoted 4 lines
Quoted 1 line
Signed-off-by AKASHI Takahiro <[email protected]>Applied to u-boot/master, thanks!
Hello Tom,
this patch causes a build error for
rpi_0_w_defconfigwithCONFIG_X509_CERTIFICATE_PARSER=y:In file included from
include/linux/time.h:4,from lib/crypto/x509_parser.h:8, from lib/crypto/x509_cert_parser.c:20: include/rtc.h:197:26: error: unknown type name ‘uchar’; did you mean ‘unchar’? void rtc_write8(int reg, uchar val); ^~~~~ uncharmake[4]: *** [
scripts/Makefile.build:279:lib/crypto/x509_cert_parser.o] Error 1The error is caused by:
Quoted 8 lines
Quoted 8 lines
include/linux/types.h:88:typedef unsigned char unchar;
I have prepared a patch but will first run it through Gitlab:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/commit/f574992867cf40f48a381f88c1ac15a47dbe1baf
@Takahiro:
I am wondering why this did not show up in your tests. Did Tom miss a patch?
Thank you for catching this, Heinrich.
Quoted 4 lines
Only sandbox enables any of this out of the box, which is why I've taken it at this point in the window. It's otherwise neutral and as good as it was going to get prior to inclusion somewhere for wider testing. Which, thanks for doing.
Yeah, more strictly speaking, my x509 test is enabled by default due to "default y" if UNIT_TEST is also enabled.
So if pytest is run on Travis CI, x509 test can also be exercised via pytest's ut driver, but pytest is run on limited number of architectures on Travis CI and UNIT_TEST is enabled only on sandbox for now.
Thanks,
-Takahiro Akashi
Quoted 2 lines
Signature · 1 line
Tom
PATCH v3 15/16 lib: crypto: add pkcs7 message parser
In reply to AKASHI TakahiroImported from linux kernel v5.3:
pkcs7.asn1 without changes
pkcs7.h with changes marked as __UBOOT__
pkcs7_parser.h without changes
pkcs7_parser.c with changes marked as __UBOOT__
--- include/crypto/pkcs7.h | 47 +++ lib/crypto/Kconfig | 10 + lib/crypto/Makefile | 11 + lib/crypto/pkcs7.asn1 | 135 ++++++++ lib/crypto/pkcs7_parser.c | 693 ++++++++++++++++++++++++++++++++++++++ lib/crypto/pkcs7_parser.h | 65 ++++ scripts/Makefile.build | 4 +- 7 files changed, 962 insertions(+), 3 deletions(-) create mode 100644 include/crypto/pkcs7.h create mode 100644 lib/crypto/pkcs7.asn1 create mode 100644 lib/crypto/pkcs7_parser.c create mode 100644 lib/crypto/pkcs7_parser.h
include/crypto/pkcs7.h new file +47 -0
@@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* PKCS#7 crypto data parser +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells (dhowells at redhat.com) +*/ + +#ifndef _CRYPTO_PKCS7_H +#define _CRYPTO_PKCS7_H + +#ifndef __UBOOT__ +#include <linux/verification.h> +#include <crypto/public_key.h> +#endif + +struct key ; +struct pkcs7_message ; + +/* +* pkcs7_parser.c +*/ +extern struct pkcs7_message *pkcs7_parse_message (const void *data, +size_t datalen); +extern void pkcs7_free_message (struct pkcs7_message *pkcs7); + +extern int pkcs7_get_content_data (const struct pkcs7_message *pkcs7, +const void **_data,size_t *_datalen, +size_t *_headerlen); + +#ifndef __UBOOT__ +/* +* pkcs7_trust.c +*/ +extern int pkcs7_validate_trust (struct pkcs7_message *pkcs7, +struct key *trust_keyring); + +/* +* pkcs7_verify.c +*/ +extern int pkcs7_verify (struct pkcs7_message *pkcs7, +enum key_being_used_for usage); + +extern int pkcs7_supply_detached_data (struct pkcs7_message *pkcs7, +const void *data,size_t datalen); +#endif + +#endif /* _CRYPTO_PKCS7_H */
lib/crypto/Kconfig +10 -0
@@ -39,4 +39,14 @@ config X509_CERTIFICATE_PARSER data and provides the ability to instantiate a crypto key from a public key packet found inside the certificate. +config PKCS7_MESSAGE_PARSER + bool "PKCS#7 message parser" + depends on X509_CERTIFICATE_PARSER + select ASN1_DECODER + select ASN1_COMPILER + select OID_REGISTRY + help + This option provides support for parsing PKCS#7 format messages for + signature data and provides the ability to verify the signature. + endif # ASYMMETRIC_KEY_TYPE
lib/crypto/Makefile +11 -0
@@ -36,3 +36,14 @@ $(obj)/x509_cert_parser.o: \ $(obj)/x509.asn1.o: $(obj)/x509.asn1.c $(obj)/x509.asn1.h $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h + +# +# PKCS#7 message handling +# +obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o +pkcs7_message-y := \ + pkcs7.asn1.o \ + pkcs7_parser.o + +$(obj)/pkcs7_parser.o: $(obj)/pkcs7.asn1.h +$(obj)/pkcs7.asn1.o: $(obj)/pkcs7.asn1.c $(obj)/pkcs7.asn1.h
lib/crypto/pkcs7.asn1 new file +135 -0
135 lines not on this page · raw message
lib/crypto/pkcs7_parser.c new file +693 -0
693 lines not on this page · raw message
lib/crypto/pkcs7_parser.h new file +65 -0
65 lines not on this page · raw message
scripts/Makefile.build +1 -3
@@ -419,11 +419,9 @@ targets += $(multi-used-y) $(multi-used-m) intermediate_targets = $(foreach sfx, $(2), \ $(patsubst %$(strip $(1)),%$(sfx), \ $(filter %$(strip $(1)), $(targets)))) -# %.asn1.o <- %.asn1.[ch] <- %.asn1 # %.lex.o <- %.lex.c <- %.l # %.tab.o <- %.tab.[ch] <- %.y -targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ - $(call intermediate_targets, .lex.o, .lex.c) \ +targets += $(call intermediate_targets, .lex.o, .lex.c) \ $(call intermediate_targets, .tab.o, .tab.c .tab.h) # Descending
Signature · 1 line
2.21.0
PATCH v3 15/16 lib: crypto: add pkcs7 message parser
Quoted 7 lines · AKASHI Takahiro
Imported from linux kernel v5.3:
pkcs7.asn1 without changes
pkcs7.hwith changes marked as__UBOOT__
pkcs7_parser.hwithout changes
pkcs7_parser.cwith changes marked as__UBOOT__Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/bd706db2/attachment.sig>
PATCH v3 16/16 test: add asn1 unit test
In reply to AKASHI TakahiroThis test will exercise asn1 compiler as well as asn1 decoder functions via various parsers.
--- test/Kconfig | 18 ++- test/lib/Makefile | 1 + test/lib/asn1.c | 392 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 test/lib/asn1.c
test/Kconfig +17 -1
@@ -12,7 +12,23 @@ config UT_LIB default y help Enables the 'ut lib' command which tests library functions like - memcat(), memcyp(), memmove(). + memcat(), memcyp(), memmove() and ASN1 compiler/decoder. + +if UT_LIB + +config UT_LIB_ASN1 + bool "Unit test for asn1 compiler and decoder function" + default y + imply ASYMMETRIC_KEY_TYPE + imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE + imply X509_CERTIFICATE_PARSER + imply PKCS7_MESSAGE_PARSER + imply RSA_PUBLIC_KEY_PARSER + help + Enables a test which exercises asn1 compiler and decoder function + via various parsers. + +endif config UT_TIME bool "Unit tests for time functions"
test/lib/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-y += hexdump.o obj-y += lmb.o obj-y += string.o obj-$(CONFIG_ERRNO_STR) += test_errno_str.o +obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
test/lib/asn1.c new file +392 -0
392 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v3 16/16 test: add asn1 unit test
Quoted 4 lines · AKASHI Takahiro
This test will exercise asn1 compiler as well as asn1 decoder functions via various parsers.
Signed-off-by AKASHI Takahiro <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191206/30e8c28f/attachment.sig>