added the seed crypto function
This commit is contained in:
@ -309,6 +309,7 @@ public:
|
||||
const Node* getTailNode () const { return this->datum_list->getTailNode (); }
|
||||
Node* getLastNode () { return this->datum_list->getTailNode (); }
|
||||
const Node* getLastNode () const { return this->datum_list->getTailNode (); }
|
||||
|
||||
protected:
|
||||
Node* find_node (const T& datum) const
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
pkgincludedir = $(includedir)/qse/cry
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
blowfish.h \
|
||||
kseed.h \
|
||||
md5.h
|
||||
|
||||
|
@ -357,6 +357,8 @@ top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = \
|
||||
blowfish.h \
|
||||
kseed.h \
|
||||
md5.h
|
||||
|
||||
all: all-am
|
||||
|
90
qse/include/qse/cry/blowfish.h
Normal file
90
qse/include/qse/cry/blowfish.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CRY_BLOWFISH_H_
|
||||
#define _QSE_CRY_BLOWFISH_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_BLOWFISH_NUM_SUBKEYS 18
|
||||
#define QSE_BLOWFISH_NUM_S_BOXES 4
|
||||
#define QSE_BLOWFISH_NUM_ENTRIES 256
|
||||
|
||||
#define QSE_BLOWFISH_MIN_KEY_LEN 4 /* bytes - 32 bits */
|
||||
#define QSE_BLOWFISH_MAX_KEY_LEN 56 /* bytes - 448 bits */
|
||||
#define QSE_BLOWFISH_BLOCK_SIZE 8 /* bytes */
|
||||
|
||||
struct qse_blowfish_t
|
||||
{
|
||||
qse_uint32_t PA[QSE_BLOWFISH_NUM_SUBKEYS];
|
||||
qse_uint32_t SB[QSE_BLOWFISH_NUM_S_BOXES][QSE_BLOWFISH_NUM_ENTRIES];
|
||||
};
|
||||
typedef struct qse_blowfish_t qse_blowfish_t;
|
||||
|
||||
|
||||
typedef qse_uint8_t (qse_blowfish_block_t)[QSE_BLOWFISH_BLOCK_SIZE];
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
QSE_EXPORT void qse_blowfish_initialize (
|
||||
qse_blowfish_t* bf,
|
||||
const void* keyptr,
|
||||
qse_size_t keylen
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_blowfish_encrypt_block (
|
||||
qse_blowfish_t* bf,
|
||||
qse_blowfish_block_t* blk
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_blowfish_decrypt_block (
|
||||
qse_blowfish_t* bf,
|
||||
qse_blowfish_block_t* blk
|
||||
);
|
||||
|
||||
/*
|
||||
QSE_EXPORT void qse_blowfish_encrypt (
|
||||
qse_blowfish_t* bf,
|
||||
void* data,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_blowfish_decrypt (
|
||||
qse_blowfish_t* bf,
|
||||
void* data,
|
||||
qse_size_t len
|
||||
);
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
87
qse/include/qse/cry/kseed.h
Normal file
87
qse/include/qse/cry/kseed.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_CRY_KSEED_H_
|
||||
#define _QSE_CRY_KSEED_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_KSEED_NUM_S_BOXES 4
|
||||
#define QSE_KSEED_NUM_ENTRIES 256
|
||||
|
||||
#define QSE_KSEED_MIN_KEY_LEN 16 /* bytes - 128 bits */
|
||||
#define QSE_KSEED_MAX_KEY_LEN 16 /* bytes - 128 bits */
|
||||
#define QSE_KSEED_BLOCK_SIZE 16 /* bytes */
|
||||
|
||||
struct qse_kseed_t
|
||||
{
|
||||
qse_uint32_t KD[32];
|
||||
};
|
||||
typedef struct qse_kseed_t qse_kseed_t;
|
||||
|
||||
typedef qse_uint8_t (qse_kseed_block_t)[QSE_KSEED_BLOCK_SIZE];
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
QSE_EXPORT void qse_kseed_initialize (
|
||||
qse_kseed_t* ks,
|
||||
const void* key,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_kseed_encrypt_block (
|
||||
qse_kseed_t* ks,
|
||||
qse_kseed_block_t* blk
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_kseed_decrypt_block (
|
||||
qse_kseed_t* ks,
|
||||
qse_kseed_block_t* blk
|
||||
);
|
||||
|
||||
/*
|
||||
QSE_EXPORT void qse_kseed_encrypt (
|
||||
qse_kseed_t* ks,
|
||||
void* data,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_kseed_decrypt (
|
||||
qse_kseed_t* ks,
|
||||
void* data,
|
||||
qse_size_t len
|
||||
);
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -346,6 +346,7 @@
|
||||
(qse_assert_failed (QSE_T(#expr), QSE_T(desc), QSE_T(__FILE__), __LINE__), 0))
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -356,6 +357,158 @@ QSE_EXPORT void qse_assert_failed (
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* INTEGER LIMITS
|
||||
* ---------------------------------------------------------------------- */
|
||||
#if defined(QSE_HAVE_UINT128_T)
|
||||
#define QSE_UINT128_MAX QSE_TYPE_UNSIGNED_MAX(qse_uint128_t)
|
||||
#define QSE_UINT128_MIN QSE_TYPE_UNSIGNED_MIN(qse_uint128_t)
|
||||
#define QSE_INT128_MAX QSE_TYPE_SIGNED_MAX(qse_int128_t)
|
||||
#define QSE_INT128_MIN QSE_TYPE_SIGNED_MIN(qse_int128_t)
|
||||
#endif
|
||||
|
||||
#if defined(QSE_HAVE_UINT64_T)
|
||||
#define QSE_UINT64_MAX QSE_TYPE_UNSIGNED_MAX(qse_uint64_t)
|
||||
#define QSE_UINT64_MIN QSE_TYPE_UNSIGNED_MIN(qse_uint64_t)
|
||||
#define QSE_INT64_MAX QSE_TYPE_SIGNED_MAX(qse_int64_t)
|
||||
#define QSE_INT64_MIN QSE_TYPE_SIGNED_MIN(qse_int64_t)
|
||||
#endif
|
||||
|
||||
#define QSE_UINT32_MAX QSE_TYPE_UNSIGNED_MAX(qse_uint32_t)
|
||||
#define QSE_UINT32_MIN QSE_TYPE_UNSIGNED_MIN(qse_uint32_t)
|
||||
#define QSE_INT32_MAX QSE_TYPE_SIGNED_MAX(qse_int32_t)
|
||||
#define QSE_INT32_MIN QSE_TYPE_SIGNED_MIN(qse_int32_t)
|
||||
|
||||
#define QSE_UINT16_MAX QSE_TYPE_UNSIGNED_MAX(qse_uint16_t)
|
||||
#define QSE_UINT16_MIN QSE_TYPE_UNSIGNED_MIN(qse_uint16_t)
|
||||
#define QSE_INT16_MAX QSE_TYPE_SIGNED_MAX(qse_int16_t)
|
||||
#define QSE_INT16_MIN QSE_TYPE_SIGNED_MIN(qse_int16_t)
|
||||
|
||||
#define QSE_UINT8_MAX QSE_TYPE_UNSIGNED_MAX(qse_uint8_t)
|
||||
#define QSE_UINT8_MIN QSE_TYPE_UNSIGNED_MIN(qse_uint8_t)
|
||||
#define QSE_INT8_MAX QSE_TYPE_SIGNED_MAX(qse_int8_t)
|
||||
#define QSE_INT8_MIN QSE_TYPE_SIGNED_MIN(qse_int8_t)
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* BIT MANIPULATIONS
|
||||
* ---------------------------------------------------------------------- */
|
||||
#if defined(QSE_HAVE_UINT64_T)
|
||||
#define QSE_FETCH64BE(ptr) \
|
||||
(((qse_uint64_t)(((qse_uint8_t*)(ptr))[0]) << 56) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[1]) << 48) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[2]) << 40) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[3]) << 32) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[4]) << 24) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[5]) << 16) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[6]) << 8) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[7])))
|
||||
|
||||
#define QSE_FETCH64LE(ptr) \
|
||||
(((qse_uint64_t)(((qse_uint8_t*)(ptr))[7]) << 56) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[6]) << 48) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[5]) << 40) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[4]) << 32) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[3]) << 24) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[2]) << 16) | \
|
||||
((qse_uint64_t)(((qse_uint8_t*)(ptr))[1]) << 8) | ((qse_uint64_t)(((qse_uint8_t*)(ptr))[0]))))
|
||||
|
||||
|
||||
|
||||
#define QSE_STORE64BE(ptr,v) do { \
|
||||
((qse_uint8_t*)(ptr))[0] = (((qse_uint64_t)(v)) >> 56) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[1] = (((qse_uint64_t)(v)) >> 48) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[2] = (((qse_uint64_t)(v)) >> 40) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[3] = (((qse_uint64_t)(v)) >> 32) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[5] = (((qse_uint64_t)(v)) >> 24) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[6] = (((qse_uint64_t)(v)) >> 16) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[7] = (((qse_uint64_t)(v)) >> 8) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[8] = (((qse_uint64_t)(v)) >> 0) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
#define QSE_STORE64LE(ptr,v) do { \
|
||||
((qse_uint8_t*)(ptr))[0] = (((qse_uint64_t)(v)) >> 0) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[1] = (((qse_uint64_t)(v)) >> 8) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[2] = (((qse_uint64_t)(v)) >> 16) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[3] = (((qse_uint64_t)(v)) >> 24) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[5] = (((qse_uint64_t)(v)) >> 32) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[6] = (((qse_uint64_t)(v)) >> 40) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[7] = (((qse_uint64_t)(v)) >> 48) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[8] = (((qse_uint64_t)(v)) >> 56) & 0xFF; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#define QSE_FETCH32BE(ptr) \
|
||||
(((qse_uint32_t)(((qse_uint8_t*)(ptr))[0]) << 24) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[1]) << 16) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[2]) << 8) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[3])))
|
||||
|
||||
#define QSE_FETCH32LE(ptr) \
|
||||
(((qse_uint32_t)(((qse_uint8_t*)(ptr))[3]) << 24) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[2]) << 16) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[1]) << 8) | \
|
||||
((qse_uint32_t)(((qse_uint8_t*)(ptr))[0])))
|
||||
|
||||
#define QSE_STORE32BE(ptr,v) do { \
|
||||
((qse_uint8_t*)(ptr))[0] = (((qse_uint32_t)(v)) >> 24) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[1] = (((qse_uint32_t)(v)) >> 16) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[2] = (((qse_uint32_t)(v)) >> 8) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[3] = (((qse_uint32_t)(v)) >> 0) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
#define QSE_STORE32LE(ptr,v) do { \
|
||||
((qse_uint8_t*)(ptr))[0] = (((qse_uint32_t)(v)) >> 0) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[1] = (((qse_uint32_t)(v)) >> 8) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[2] = (((qse_uint32_t)(v)) >> 16) & 0xFF; \
|
||||
((qse_uint8_t*)(ptr))[3] = (((qse_uint32_t)(v)) >> 24) & 0xFF; \
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
#define QSE_ROTL_INTERNAL(type_t,x,y,nbits) \
|
||||
(((x) << ((y) & ((nbits) - 1))) | ((x) >> ((type_t)(nbits) - ((y) & ((nbits) - 1)))))
|
||||
#define QSE_ROTR_INTERNAL(type_t,x,y,nbits) \
|
||||
(((x) >> ((y) & ((nbits) - 1))) | ((x) << ((type_t)(nbits) - ((y) & ((nbits) - 1)))))
|
||||
|
||||
#if defined(QSE_HAVE_UINT64_T)
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(INTEL_CC) && defined(__GNUC__) && (defined(__i386) || defined(i386) || defined(__x86_64) || defined(__amd64))
|
||||
static inline qse_uint64_t QSE_ROTL64 (qse_uint64_t v, int i)
|
||||
{
|
||||
__asm__ volatile ("rolq %%cl,%0": "=r"(v): "0"(v), "c"(i): /* no clobbers */);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline qse_uint64_t QSE_ROTR64 (qse_uint64_t v, int i)
|
||||
{
|
||||
__asm__ volatile ("rorq %%cl,%0" :"=r"(v) :"0"(v), "c"(i): /* no clobbers */);
|
||||
return v;
|
||||
}
|
||||
#else
|
||||
|
||||
# define QSE_ROTL64(x,y) QSE_ROTL_INTERNAL(qse_uint64_t, (qse_uint64_t)x, (qse_uint64_t)y, 64)
|
||||
# define QSE_ROTR64(x,y) QSE_ROTR_INTERNAL(qse_uint64_t, (qse_uint64_t)x, (qse_uint64_t)y, 64)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(INTEL_CC) && defined(__GNUC__) && (defined(__i386) || defined(i386) || defined(__x86_64) || defined(__amd64))
|
||||
static inline qse_uint32_t QSE_ROTL32 (qse_uint32_t v, int i)
|
||||
{
|
||||
__asm__ volatile ("roll %%cl,%0": "=r"(v): "0"(v), "c"(i): /* no clobbers */);
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline qse_uint32_t QSE_ROTR32 (qse_uint32_t v, int i)
|
||||
{
|
||||
__asm__ volatile ("rorl %%cl,%0" :"=r"(v) :"0"(v), "c"(i): /* no clobbers */);
|
||||
return v;
|
||||
}
|
||||
#else
|
||||
|
||||
# define QSE_ROTL32(x,y) QSE_ROTL_INTERNAL(qse_uint32_t, (qse_uint32_t)x, (qse_uint32_t)y, 32)
|
||||
# define QSE_ROTR32(x,y) QSE_ROTR_INTERNAL(qse_uint32_t, (qse_uint32_t)x, (qse_uint32_t)y, 32)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* C++ NAMESPACE
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user