added qse_encode_hmacmbs()/qse_encode_hmacwcs()/qse_decode_hmacmbs()/qse_decode_hmacwcs()
This commit is contained in:
parent
2f07153431
commit
94cc9298c1
@ -165,7 +165,7 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \
|
||||
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
||||
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
||||
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing README \
|
||||
ac/ar-lib ac/compile ac/config.guess ac/config.sub \
|
||||
ac/ar-lib ac/compile ac/config.guess ac/config.sub ac/depcomp \
|
||||
ac/install-sh ac/ltmain.sh ac/missing
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
distdir = $(PACKAGE)-$(VERSION)
|
||||
|
20
qse/configure
vendored
20
qse/configure
vendored
@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for qse 0.8.2.
|
||||
# Generated by GNU Autoconf 2.69 for qse 0.8.3.
|
||||
#
|
||||
# Report bugs to <Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)>.
|
||||
#
|
||||
@ -590,8 +590,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='qse'
|
||||
PACKAGE_TARNAME='qse'
|
||||
PACKAGE_VERSION='0.8.2'
|
||||
PACKAGE_STRING='qse 0.8.2'
|
||||
PACKAGE_VERSION='0.8.3'
|
||||
PACKAGE_STRING='qse 0.8.3'
|
||||
PACKAGE_BUGREPORT='Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)'
|
||||
PACKAGE_URL='http://code.miflux.com/@qse'
|
||||
|
||||
@ -1414,7 +1414,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures qse 0.8.2 to adapt to many kinds of systems.
|
||||
\`configure' configures qse 0.8.3 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@ -1484,7 +1484,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of qse 0.8.2:";;
|
||||
short | recursive ) echo "Configuration of qse 0.8.3:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@ -1629,7 +1629,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
qse configure 0.8.2
|
||||
qse configure 0.8.3
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@ -2413,7 +2413,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by qse $as_me 0.8.2, which was
|
||||
It was created by qse $as_me 0.8.3, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@ -3288,7 +3288,7 @@ fi
|
||||
|
||||
# Define the identity of the package.
|
||||
PACKAGE='qse'
|
||||
VERSION='0.8.2'
|
||||
VERSION='0.8.3'
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
@ -24323,7 +24323,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by qse $as_me 0.8.2, which was
|
||||
This file was extended by qse $as_me 0.8.3, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@ -24390,7 +24390,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
qse config.status 0.8.2
|
||||
qse config.status 0.8.3
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
@ -4,7 +4,7 @@ dnl Make sure you change the version information
|
||||
dnl in include/qse/conf_*.h whenever you change the version
|
||||
dnl here. Those files don't depend on autoconf, thus requiring
|
||||
dnl manual change.
|
||||
AC_INIT([qse],[0.8.2],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.miflux.com/@qse])
|
||||
AC_INIT([qse],[0.8.3],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.miflux.com/@qse])
|
||||
|
||||
AC_CONFIG_HEADER([include/qse/config.h])
|
||||
AC_CONFIG_AUX_DIR([ac])
|
||||
|
@ -105,7 +105,7 @@ qse_size_t qse_get_hmac_block_size (
|
||||
* prefixed with hmac followed by the pair values encoded in hexdecimal
|
||||
* digits seperated by a dash
|
||||
*/
|
||||
qse_mchar_t* qse_encode_hmacstr (
|
||||
qse_mchar_t* qse_encode_hmacmbs (
|
||||
qse_hmac_sha_type_t sha_type,
|
||||
const qse_uint8_t* keyptr,
|
||||
qse_size_t keylen,
|
||||
@ -114,16 +114,43 @@ qse_mchar_t* qse_encode_hmacstr (
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_xptl_t* qse_decode_hmacstr (
|
||||
qse_xptl_t* qse_decode_hmacmbs (
|
||||
qse_hmac_sha_type_t sha_type,
|
||||
const qse_uint8_t* keyptr,
|
||||
qse_size_t keylen,
|
||||
const qse_mchar_t* hmacstr,
|
||||
const qse_mchar_t* hmacmbs,
|
||||
qse_size_t* count,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
|
||||
qse_wchar_t* qse_encode_hmacwcs (
|
||||
qse_hmac_sha_type_t sha_type,
|
||||
const qse_uint8_t* keyptr,
|
||||
qse_size_t keylen,
|
||||
qse_xptl_t* data,
|
||||
qse_size_t count,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_xptl_t* qse_decode_hmacwcs (
|
||||
qse_hmac_sha_type_t sha_type,
|
||||
const qse_uint8_t* keyptr,
|
||||
qse_size_t keylen,
|
||||
const qse_wchar_t* hmacwcs,
|
||||
qse_size_t* count,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_encode_hmacstr qse_encode_hmacmbs
|
||||
# define qse_decode_hmacstr qse_decode_hmacmbs
|
||||
#else
|
||||
# define qse_encode_hmacstr qse_encode_hmacwcs
|
||||
# define qse_decode_hmacstr qse_decode_hmacwcs
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <qse/Types.hpp>
|
||||
#include <qse/Uncopyable.hpp>
|
||||
#include <qse/cmn/Mmgr.hpp>
|
||||
#include <qse/si/mtx.h>
|
||||
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
|
@ -245,8 +245,9 @@ qse_size_t qse_hmac_digest (qse_hmac_t* ctx, qse_uint8_t* digest, qse_size_t siz
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
qse_mchar_t* qse_encode_hmacstr (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, qse_xptl_t* data, qse_size_t count, qse_mmgr_t* mmgr)
|
||||
qse_mchar_t* qse_encode_hmacmbs (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, qse_xptl_t* data, qse_size_t count, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_size_t reqsize = 0, i , j;
|
||||
qse_mchar_t* buf, * ptr;
|
||||
@ -277,13 +278,14 @@ qse_mchar_t* qse_encode_hmacstr (qse_hmac_sha_type_t sha_type, const qse_uint8_t
|
||||
qse_hmac_digest (&hmac, digest, digest_len);
|
||||
|
||||
ptr = buf;
|
||||
for (i = 0; i < digest_len; i++) ptr += qse_mbsfmt(ptr, ("%02x"), digest[i]);
|
||||
for (i = 0; i < digest_len; i++) ptr += qse_mbsfmt(ptr, QSE_MT("%02x"), digest[i]);
|
||||
*ptr = '-';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_xptl_t* qse_decode_hmacstr (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, const qse_mchar_t* hmacstr, qse_size_t* count, qse_mmgr_t* mmgr)
|
||||
|
||||
qse_xptl_t* qse_decode_hmacmbs (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, const qse_mchar_t* hmacstr, qse_size_t* count, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_uint8_t digest[QSE_HMAC_MAX_DIGEST_LEN];
|
||||
qse_uint8_t orgdig[QSE_HMAC_MAX_DIGEST_LEN];
|
||||
@ -352,3 +354,114 @@ qse_xptl_t* qse_decode_hmacstr (qse_hmac_sha_type_t sha_type, const qse_uint8_t*
|
||||
*count = segcount;
|
||||
return (qse_xptl_t*)data;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
qse_wchar_t* qse_encode_hmacwcs (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, qse_xptl_t* data, qse_size_t count, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_size_t reqsize = 0, i , j;
|
||||
qse_wchar_t* buf, * ptr;
|
||||
qse_xptl_t* dptr;
|
||||
qse_hmac_t hmac;
|
||||
qse_uint8_t digest[QSE_HMAC_MAX_DIGEST_LEN];
|
||||
qse_size_t digest_len = sha_digest_size(sha_type);
|
||||
|
||||
for (i = 0, dptr = data; i < count; i++, dptr++) reqsize += 1 + (dptr->len * 2);
|
||||
reqsize += digest_len * 2 + 1;
|
||||
|
||||
buf = (qse_wchar_t*)QSE_MMGR_ALLOC(mmgr, reqsize * QSE_SIZEOF(*buf));
|
||||
if (!buf) return QSE_NULL;
|
||||
|
||||
ptr = &buf[digest_len * 2 + 1];
|
||||
for (i = 0, dptr = data; i < count; i++, dptr++)
|
||||
{
|
||||
for (j = 0; j < dptr->len; j++)
|
||||
{
|
||||
ptr += qse_wcsfmt(ptr, QSE_WT("%02x"), *((qse_uint8_t*)dptr->ptr + j));
|
||||
}
|
||||
if (i < count - 1) *ptr++ = QSE_WT('-');
|
||||
}
|
||||
*ptr = '\0';
|
||||
|
||||
qse_hmac_initialize (&hmac, sha_type, keyptr, keylen);
|
||||
qse_hmac_update (&hmac, (const qse_uint8_t*)&buf[digest_len * 2 + 1], ptr - &buf[digest_len * 2 + 1]);
|
||||
qse_hmac_digest (&hmac, digest, digest_len);
|
||||
|
||||
ptr = buf;
|
||||
for (i = 0; i < digest_len; i++) ptr += qse_wcsfmt(ptr, QSE_WT("%02x"), digest[i]);
|
||||
*ptr = '-';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
qse_xptl_t* qse_decode_hmacwcs (qse_hmac_sha_type_t sha_type, const qse_uint8_t* keyptr, qse_size_t keylen, const qse_wchar_t* hmacstr, qse_size_t* count, qse_mmgr_t* mmgr)
|
||||
{
|
||||
qse_uint8_t digest[QSE_HMAC_MAX_DIGEST_LEN];
|
||||
qse_uint8_t orgdig[QSE_HMAC_MAX_DIGEST_LEN];
|
||||
qse_size_t digest_len = sha_digest_size(sha_type);
|
||||
const qse_wchar_t* ptr, * segptr, * segstart;
|
||||
qse_size_t seglen, reqlen = 0, segcount = 0, i;
|
||||
qse_uint8_t* data, * uptr;
|
||||
qse_xptl_t* xptl;
|
||||
qse_hmac_t hmac;
|
||||
|
||||
for (ptr = hmacstr, i = 0; *ptr != QSE_WT('\0') && *ptr != QSE_WT('-'); ptr += 2, i++)
|
||||
{
|
||||
if (!QSE_ISWXDIGIT(ptr[0]) || !QSE_ISWXDIGIT(ptr[1])) return QSE_NULL;
|
||||
if (i >= digest_len) return QSE_NULL; /* digest too long */
|
||||
orgdig[i] = QSE_WXDIGITTONUM(ptr[0]) * 16 + QSE_WXDIGITTONUM(ptr[1]);
|
||||
}
|
||||
|
||||
if (*ptr == QSE_WT('\0')) return QSE_NULL; /* no dash found after digest */
|
||||
if (i != digest_len) return QSE_NULL; /* digest too short */
|
||||
ptr++;
|
||||
qse_hmac_initialize (&hmac, sha_type, keyptr, keylen);
|
||||
qse_hmac_update (&hmac, (const qse_uint8_t*)ptr, qse_wcslen(ptr));
|
||||
qse_hmac_digest (&hmac, digest, digest_len);
|
||||
|
||||
if (QSE_MEMCMP(digest, orgdig, digest_len) != 0) return QSE_NULL; /* wrong hmac */
|
||||
|
||||
segstart = ptr;
|
||||
while (1)
|
||||
{
|
||||
segptr = ptr;
|
||||
|
||||
for (ptr = segptr; *ptr != QSE_WT('\0') && *ptr != QSE_WT('-'); ptr++) ;
|
||||
seglen = ptr - segptr;
|
||||
|
||||
if (seglen & 1) return QSE_NULL; /* odd-length segment */
|
||||
|
||||
reqlen += (seglen >> 1) + QSE_SIZEOF(*xptl);
|
||||
segcount++;
|
||||
|
||||
if (*ptr == QSE_WT('\0')) break;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
data = (qse_uint8_t*)QSE_MMGR_ALLOC(mmgr, reqlen);
|
||||
if (!data) return QSE_NULL;
|
||||
|
||||
ptr = segstart;
|
||||
xptl = (qse_xptl_t*)data;
|
||||
uptr = data + (segcount * QSE_SIZEOF(*xptl));
|
||||
while (1)
|
||||
{
|
||||
segptr = ptr;
|
||||
|
||||
xptl->ptr = uptr;
|
||||
for (ptr = segptr, i = 0; *ptr != QSE_WT('\0') && *ptr != QSE_WT('-'); ptr += 2, i++)
|
||||
{
|
||||
*uptr++ = QSE_WXDIGITTONUM(ptr[0]) * 16 + QSE_WXDIGITTONUM(ptr[1]);
|
||||
}
|
||||
xptl->len = i;
|
||||
xptl++;
|
||||
|
||||
if (*ptr == QSE_WT('\0')) break;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
*count = segcount;
|
||||
return (qse_xptl_t*)data;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user