Hi Raymond On Tue, 2 Jul 2024 at 21:30, Raymond Mao <raymond....@linaro.org> wrote: > > Move pkcs7_get_content_data as a helper function that can be > shared by legacy crypto lib and MbedTLS implementation. > > Signed-off-by: Raymond Mao <raymond....@linaro.org> > --- > Changes in v4 > - Initial patch. > > lib/crypto/Makefile | 1 + > lib/crypto/pkcs7_helper.c | 40 +++++++++++++++++++++++++++++++++++++++ > lib/crypto/pkcs7_parser.c | 28 --------------------------- > 3 files changed, 41 insertions(+), 28 deletions(-) > create mode 100644 lib/crypto/pkcs7_helper.c > > diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile > index 946cc3a7b59..16059088f26 100644 > --- a/lib/crypto/Makefile > +++ b/lib/crypto/Makefile > @@ -53,6 +53,7 @@ $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c > $(obj)/x509_akid.asn1.h > obj-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER) += pkcs7_message.o > pkcs7_message-y := \ > pkcs7.asn1.o \ > + pkcs7_helper.o \ > pkcs7_parser.o > obj-$(CONFIG_$(SPL_)PKCS7_VERIFY) += pkcs7_verify.o > > diff --git a/lib/crypto/pkcs7_helper.c b/lib/crypto/pkcs7_helper.c > new file mode 100644 > index 00000000000..6c8dcd1a935 > --- /dev/null > +++ b/lib/crypto/pkcs7_helper.c > @@ -0,0 +1,40 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * PKCS7 helper functions > + * > + * Copyright (c) 2012 Red Hat, Inc. All Rights Reserved. > + * Written by David Howells (dhowe...@redhat.com) > + * > + * Copyright (c) 2024 Linaro Limited > + * Author: Raymond Mao <raymond....@linaro.org>
Copyright and authorship is added if you add a significant portion of the file. You are moving a function around here, so just keep the original author & copyright > + */ > +#include <linux/kernel.h> > +#include <linux/err.h> > +#include <crypto/pkcs7_parser.h> > + > +/** > + * pkcs7_get_content_data - Get access to the PKCS#7 content > + * @pkcs7: The preparsed PKCS#7 message to access > + * @_data: Place to return a pointer to the data > + * @_data_len: Place to return the data length > + * @_headerlen: Size of ASN.1 header not included in _data > + * > + * Get access to the data content of the PKCS#7 message. The size of the > + * header of the ASN.1 object that contains it is also provided and can be > used > + * to adjust *_data and *_data_len to get the entire object. > + * > + * Returns -ENODATA if the data object was missing from the message. > + */ > +int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, > + const void **_data, size_t *_data_len, > + size_t *_headerlen) > +{ > + if (!pkcs7->data) > + return -ENODATA; > + > + *_data = pkcs7->data; > + *_data_len = pkcs7->data_len; > + if (_headerlen) > + *_headerlen = pkcs7->data_hdrlen; > + return 0; > +} > diff --git a/lib/crypto/pkcs7_parser.c b/lib/crypto/pkcs7_parser.c > index d5efa828d6a..c849dc0d92d 100644 > --- a/lib/crypto/pkcs7_parser.c > +++ b/lib/crypto/pkcs7_parser.c > @@ -182,34 +182,6 @@ out_no_ctx: > } > EXPORT_SYMBOL_GPL(pkcs7_parse_message); > > -/** > - * pkcs7_get_content_data - Get access to the PKCS#7 content > - * @pkcs7: The preparsed PKCS#7 message to access > - * @_data: Place to return a pointer to the data > - * @_data_len: Place to return the data length > - * @_headerlen: Size of ASN.1 header not included in _data > - * > - * Get access to the data content of the PKCS#7 message. The size of the > - * header of the ASN.1 object that contains it is also provided and can be > used > - * to adjust *_data and *_data_len to get the entire object. > - * > - * Returns -ENODATA if the data object was missing from the message. > - */ > -int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, > - const void **_data, size_t *_data_len, > - size_t *_headerlen) > -{ > - if (!pkcs7->data) > - return -ENODATA; > - > - *_data = pkcs7->data; > - *_data_len = pkcs7->data_len; > - if (_headerlen) > - *_headerlen = pkcs7->data_hdrlen; > - return 0; > -} > -EXPORT_SYMBOL_GPL(pkcs7_get_content_data); > - > /* > * Note an OID when we find one for later processing when we know how > * to interpret it. > -- > 2.25.1 > with the above fixed Reviewed-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>