[PATCH v2 06/10] tls: Add helper to find hash function by id
Denis Kenzior <[email protected]>
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
Instead of open-coding a loop to map the hash id from
SignatureAndHashAlgorithm structure to a supported hash function.
---
ell/tls-suites.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/ell/tls-suites.c b/ell/tls-suites.c
index d5d2ec8f741f..bc6a756422b3 100644
--- a/ell/tls-suites.c
+++ b/ell/tls-suites.c
@@ -47,6 +47,17 @@ enum signature_algorithm {
SIGNATURE_ALGORITHM_ECDSA = 3,
};
+static enum handshake_hash_type find_hash_by_id(uint8_t id)
+{
+ enum handshake_hash_type hash;
+
+ for (hash = 0; hash < __HANDSHAKE_HASH_COUNT; hash++)
+ if (tls_handshake_hash_data[hash].tls_id == id)
+ break;
+
+ return hash;
+}
+
/*
* Sanitize DigitallySigned struct input, making sure the lengths
* are valid and correspond to what we expect.
@@ -182,11 +193,7 @@ static bool tls_rsa_verify(struct l_tls *tls, const uint8_t *in, size_t in_len,
}
if (tls->negotiated_version >= L_TLS_V12) {
- enum handshake_hash_type hash;
-
- for (hash = 0; hash < __HANDSHAKE_HASH_COUNT; hash++)
- if (tls_handshake_hash_data[hash].tls_id == in[0])
- break;
+ enum handshake_hash_type hash = find_hash_by_id(in[0]);
if (hash == __HANDSHAKE_HASH_COUNT) {
TLS_DISCONNECT(TLS_ALERT_DECRYPT_ERROR, 0,
--
2.35.1