From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Lei He <helei.sig11@bytedance.com>
Cc: mst@redhat.com, arei.gonglei@huawei.com, qemu-devel@nongnu.org,
pizhenwei@bytedance.com, jasowang@redhat.com
Subject: Re: [PATCH 2/7] crypto: Support more ASN.1 types
Date: Fri, 17 Jun 2022 12:20:15 +0100 [thread overview]
Message-ID: <Yqxjb/9WTSmv5Kjw@redhat.com> (raw)
In-Reply-To: <20220613084531.8086-3-helei.sig11@bytedance.com>
On Mon, Jun 13, 2022 at 04:45:26PM +0800, Lei He wrote:
> 1. support decoding of 'bit string','octet string',
> 'object id', and 'context specific tag' for DER decoder.
> 2. support encoding of int and sequence for DER decoder.
> 3. add test suites for the above changes.
>
> Signed-off-by: lei he <helei.sig11@bytedance.com>
> ---
> crypto/der.c | 174 +++++++++++++++++++++++++++++++++++++------
> crypto/der.h | 128 ++++++++++++++++++++++++++++++-
> tests/unit/test-crypto-der.c | 126 +++++++++++++++++++++++++------
> 3 files changed, 382 insertions(+), 46 deletions(-)
>
> diff --git a/crypto/der.c b/crypto/der.c
> index f877390bbb..edf2c6c313 100644
> --- a/crypto/der.c
> +++ b/crypto/der.c
> @@ -27,15 +27,68 @@ enum QCryptoDERTypeTag {
> QCRYPTO_DER_TYPE_TAG_INT = 0x2,
> QCRYPTO_DER_TYPE_TAG_BIT_STR = 0x3,
> QCRYPTO_DER_TYPE_TAG_OCT_STR = 0x4,
> - QCRYPTO_DER_TYPE_TAG_OCT_NULL = 0x5,
> - QCRYPTO_DER_TYPE_TAG_OCT_OID = 0x6,
> + QCRYPTO_DER_TYPE_TAG_NULL = 0x5,
> + QCRYPTO_DER_TYPE_TAG_OID = 0x6,
> QCRYPTO_DER_TYPE_TAG_SEQ = 0x10,
> QCRYPTO_DER_TYPE_TAG_SET = 0x11,
> };
>
> -#define QCRYPTO_DER_CONSTRUCTED_MASK 0x20
> +enum QCryptoDERTagClass {
> + QCRYPTO_DER_TAG_CLASS_UNIV = 0x0,
> + QCRYPTO_DER_TAG_CLASS_APPL = 0x1,
> + QCRYPTO_DER_TAG_CLASS_CONT = 0x2,
> + QCRYPTO_DER_TAG_CLASS_PRIV = 0x3,
> +};
> +
> +enum QCryptoDERTagEnc {
> + QCRYPTO_DER_TAG_ENC_PRIM = 0x0,
> + QCRYPTO_DER_TAG_ENC_CONS = 0x1,
> +};
> +
> +#define QCRYPTO_DER_TAG_ENC_MASK 0x20
> +#define QCRYPTO_DER_TAG_ENC_SHIFT 5
> +
> +#define QCRYPTO_DER_TAG_CLASS_MASK 0xc0
> +#define QCRYPTO_DER_TAG_CLASS_SHIFT 6
> +
> +#define QCRYPTO_DER_TAG_VAL_MASK 0x1f
> #define QCRYPTO_DER_SHORT_LEN_MASK 0x80
>
> +#define QCRYPTO_DER_TAG(class, enc, val) \
> + (((class) << QCRYPTO_DER_TAG_CLASS_SHIFT) | \
> + ((enc) << QCRYPTO_DER_TAG_ENC_SHIFT) | val)
> +
> +static void qcrypto_der_encode_data(const uint8_t *src, size_t src_len,
> + uint8_t *dst, size_t *dst_len)
> +{
> + size_t max_length = 0xFF;
> + uint8_t length_bytes = 0, header_byte;
> +
> + if (src_len < QCRYPTO_DER_SHORT_LEN_MASK) {
> + header_byte = src_len;
> + *dst_len = src_len + 1;
> + } else {
> + for (length_bytes = 1; max_length < src_len;) {
> + length_bytes++;
> + max_length = (max_length << 8) + max_length;
> + }
Can't length_bytes++ be in the for clause like:
for (length_bytes = 1; max_length < src_len;length_bytes++) {
max_length = (max_length << 8) + max_length;
}
?
Aside from that minor nitpick
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-06-17 11:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 8:45 [PATCH 0/7] crypto: Introduce ECDSA algorithm Lei He
2022-06-13 8:45 ` [PATCH 1/7] crypto: Introduce ECDSA algorithm API Lei He
2022-06-14 6:51 ` Philippe Mathieu-Daudé via
2022-06-17 11:14 ` Daniel P. Berrangé
2022-06-13 8:45 ` [PATCH 2/7] crypto: Support more ASN.1 types Lei He
2022-06-17 11:20 ` Daniel P. Berrangé [this message]
2022-06-13 8:45 ` [PATCH 3/7] crypto: remove "qemu/osdep.h" in rsakey.h Lei He
2022-06-13 13:55 ` Philippe Mathieu-Daudé via
2022-06-17 11:20 ` Daniel P. Berrangé
2022-06-13 8:45 ` [PATCH 4/7] crypto: Add ECDSA key parser Lei He
2022-06-13 14:19 ` Philippe Mathieu-Daudé via
2022-06-14 1:43 ` [Phishing Risk] [External] " 何磊
2022-06-14 6:48 ` Philippe Mathieu-Daudé via
2022-06-16 16:44 ` Michael S. Tsirkin
2022-06-17 11:34 ` Daniel P. Berrangé
2022-06-13 8:45 ` [PATCH 5/7] crypto: Implement ECDSA algorithm by hogweed Lei He
2022-06-17 11:35 ` Daniel P. Berrangé
2022-06-13 8:45 ` [PATCH 6/7] crypto: Implement ECDSA algorithm by gcrypt Lei He
2022-06-17 13:41 ` Daniel P. Berrangé
2022-06-13 8:45 ` [PATCH 7/7] crypto: Add test suite for ECDSA algorithm Lei He
2022-06-17 13:42 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yqxjb/9WTSmv5Kjw@redhat.com \
--to=berrange@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=helei.sig11@bytedance.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pizhenwei@bytedance.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).