Welcome! Log In Create A New Profile

Advanced

[PATCH 1 of 2] Core: add function to decode hexadecimal strings

Nate Karstens
July 28, 2017 02:48PM
# HG changeset patch
# User Nate Karstens <nate.karstens@garmin.com>
# Date 1501265787 18000
# Fri Jul 28 13:16:27 2017 -0500
# Node ID 7e10e1dc1fae0f538a0a74fd6783f9b33a905933
# Parent 72d3aefc2993a639cc8cddc94aefc7c4390ee252
Core: add function to decode hexadecimal strings.

Adds functionality to convert a hexadecimal string into binary data.
This will be used to decode PSKs stored in hexadecimal representation.

Signed-off-by: Nate Karstens <nate.karstens@garmin.com>

diff -r 72d3aefc2993 -r 7e10e1dc1fae src/core/ngx_string.c
--- a/src/core/ngx_string.c Wed Jul 26 13:13:51 2017 +0300
+++ b/src/core/ngx_string.c Fri Jul 28 13:16:27 2017 -0500
@@ -1104,6 +1104,54 @@ ngx_hextoi(u_char *line, size_t n)
}


+ngx_int_t
+ngx_hex_decode(u_char *dst, size_t dlen, u_char *src, size_t slen)
+{
+ u_char c, ch;
+ ngx_int_t len;
+
+ if ((slen & 1) || (dlen < (slen / 2))) {
+ return NGX_ERROR;
+ }
+
+ len = slen / 2;
+
+ while (slen > 0) {
+ ch = *src;
+ c = (u_char) (ch | 0x20);
+
+ if (ch >= '0' && ch <= '9') {
+ *dst = ch - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ *dst = c - 'a' + 10;
+ } else {
+ return NGX_ERROR;
+ }
+
+ *dst <<= 4;
+ src++;
+
+ ch = *src;
+ c = (u_char) (ch | 0x20);
+
+ if (ch >= '0' && ch <= '9') {
+ *dst |= ch - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ *dst |= c - 'a' + 10;
+ } else {
+ return NGX_ERROR;
+ }
+
+ dst++;
+ src++;
+
+ slen -= 2;
+ }
+
+ return len;
+}
+
+
u_char *
ngx_hex_dump(u_char *dst, u_char *src, size_t len)
{
diff -r 72d3aefc2993 -r 7e10e1dc1fae src/core/ngx_string.h
--- a/src/core/ngx_string.h Wed Jul 26 13:13:51 2017 +0300
+++ b/src/core/ngx_string.h Fri Jul 28 13:16:27 2017 -0500
@@ -176,6 +176,7 @@ off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);

+ngx_int_t ngx_hex_decode(u_char *dst, size_t dlen, u_char *src, size_t slen);
u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);



________________________________

CONFIDENTIALITY NOTICE: This email and any attachments are for the sole use of the intended recipient(s) and contain information that may be Garmin confidential and/or Garmin legally privileged. If you have received this email in error, please notify the sender by reply email and delete the message. Any disclosure, copying, distribution or use of this communication (including attachments) by someone other than the intended recipient is prohibited. Thank you.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 2] [PATCH 1+2 of 4]

Nate Karstens 500 July 28, 2017 02:48PM

[PATCH 2 of 2] SSL: add connection support

Nate Karstens 242 July 28, 2017 02:48PM

Re: [PATCH 2 of 2] SSL: add connection support

Maxim Dounin 229 August 21, 2017 07:42PM

[PATCH 1 of 2] Core: add function to decode hexadecimal strings

Nate Karstens 206 July 28, 2017 02:48PM

Re: [PATCH 1 of 2] Core: add function to decode hexadecimal strings

Maxim Dounin 426 August 21, 2017 07:42PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 169
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready