aboutsummaryrefslogtreecommitdiffstats
path: root/com32/libutil/unbase64.c
diff options
context:
space:
mode:
authorhpa <hpa>2005-01-21 00:49:46 +0000
committerhpa <hpa>2005-01-21 00:49:46 +0000
commite8d5cb2b20b82c4e30942834fad8ddb1592bb1db (patch)
treed968800a7b80406059ba06508b84ed62ddfd89db /com32/libutil/unbase64.c
parentf7c564216b2d987a1b0b30602fd33536c7f4276e (diff)
downloadsyslinux-e8d5cb2b20b82c4e30942834fad8ddb1592bb1db.tar.gz
syslinux-e8d5cb2b20b82c4e30942834fad8ddb1592bb1db.tar.xz
syslinux-e8d5cb2b20b82c4e30942834fad8ddb1592bb1db.zip
More work on password support for the menu systems. Make the base64
decoder work (necessary to handle encrypted passwords.) Simple SHA-1 password generator in Perl.
Diffstat (limited to 'com32/libutil/unbase64.c')
-rw-r--r--com32/libutil/unbase64.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/com32/libutil/unbase64.c b/com32/libutil/unbase64.c
new file mode 100644
index 00000000..83007d3a
--- /dev/null
+++ b/com32/libutil/unbase64.c
@@ -0,0 +1,78 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2005 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * unbase64.c
+ *
+ * Convert a string in base64 format to a byte array.
+ */
+
+#include <string.h>
+#include <base64.h>
+
+static const unsigned char _base64chars[] =
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./";
+
+size_t unbase64(unsigned char *buffer, size_t bufsiz, const char *txt)
+{
+ unsigned int bits = 0;
+ int nbits = 0;
+ char base64tbl[256];
+ int i;
+ char v;
+ size_t nbytes = 0;
+
+
+ memset(base64tbl, -1, sizeof base64tbl);
+
+ for ( i = 0 ; _base64chars[i] ; i++ ) {
+ base64tbl[_base64chars[i]] = i;
+ }
+
+ /* Also support filesystem safe alternate base64 encoding */
+ base64tbl['-'] = 62;
+ base64tbl['_'] = 63;
+
+ while ( *txt ) {
+ if ( (v = base64tbl[(unsigned char) *txt]) >= 0 ) {
+ bits <<= 6;
+ bits += v;
+ nbits += 6;
+ if ( nbits >= 8 ) {
+ if ( nbytes < bufsiz )
+ *buffer++ = (bits >> (nbits-8));
+ nbytes++;
+ nbits -= 8;
+ }
+ }
+ txt++;
+ }
+
+ return nbytes;
+}
+