* hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p)
* hbytes blockcipher d|e VAR ALG KEY MODE [IV] => IV
* hbytes blockcipher mac MSG ALG KEY MODE IV => final block
+ * hbytes blockcipher prop PROPERTY ALG => property value
*
* hbytes hash ALG MESSAGE => hash
* hbytes hmac ALG MESSAGE KEY [MACLENGTH] => mac
+ * hbytes hash-prop PROPERTY ALG => property value
*
* ulong ul2int ULONG => INT can fail if >INT_MAX
* ulong int2ul INT => ULONG can fail if <0
/* from algtables.c */
+typedef struct {
+ const char *name;
+ int int_offset;
+} BlockCipherPropInfo, HashAlgPropInfo;
+
typedef struct {
const char *name;
int hashsize, blocksize, statesize;
key obj
?maclen obj
=> hb
+ hash-prop
+ prop enum(HashAlgPropInfo, "prop")
+ alg enum(HashAlgInfo, "alg")
+ => int
Table dgram_socket DgramSocket_SubCommand
create
mode enum(BlockCipherModeInfo, "mode")
iv hb
=> hb
+ prop -1
+ prop enum(BlockCipherPropInfo, "prop")
+ alg enum(BlockCipherAlgInfo, "alg")
+ => int
EntryExtra BlockCipherOp
int encrypt;
bcmode.o \
misc.o \
algtables.o \
- serpent.o \
crypto.o \
parse.o
HDRS= hbytes.h \
- serpent.h \
$(AUTO_HDRS)
AUTO_HDRS= tables.h
%.o: %.c $(HDRS)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
-serpent.o: serpent.c serpent.h serpentsboxes.h
- $(CC_CRYPTO) -o $@ -c $<
+#alg.o: alg.c alg.h alg2.h
+# $(CC_CRYPTO) -o $@ -c $<
clean:
rm -f $(OBJS) $(TARGETS) *~ ./#*#
#include <netinet/in.h>
#include "hbytes.h"
-#include "serpent.h"
#include <nettle/md5.h>
#include <nettle/sha.h>
+#include <nettle/serpent.h>
+#include <nettle/twofish.h>
+#include <nettle/aes.h>
+#include <nettle/blowfish.h>
-static void alg_serpent_makekey(void *schedule, const void *key, int keylen) {
- serpent_makekey(schedule, key, keylen);
-}
+#define NETTLE_BLOCKCIPHERS \
+ DO(serpent, SERPENT) \
+ DO(twofish, TWOFISH) \
+ DO(aes, AES) \
+ DO(blowfish, BLOWFISH) \
+ ALIAS(rijndael, aes, AES)
-static void alg_serpent_encrypt(const void *sch, const void *in, void *out) {
- serpent_encrypt(in, out, sch);
-}
-
-static void alg_serpent_decrypt(const void *sch, const void *in, void *out) {
- serpent_decrypt(in, out, sch);
-}
+#define ALIAS(alias,name,NAME)
+#define DO(name,NAME) \
+ static void alg_##name##_makekey(void *sch, const void *key, int keylen) { \
+ name##_set_key(sch, keylen, key); \
+ } \
+ static void alg_##name##_encr(const void *sch, const void *in, void *out) { \
+ ##name##_encrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
+ } \
+ static void alg_##name##_decr(const void *sch, const void *in, void *out) { \
+ ##name##_decrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
+ }
+ NETTLE_BLOCKCIPHERS
+#undef DO
+#undef ALIAS
const BlockCipherAlgInfo blockcipheralginfos[]= {
- { "serpent", 16, sizeof(SerpentKeySchedule), 16,32,
- serpent_byteswap_block,
- { alg_serpent_makekey, alg_serpent_encrypt },
- { alg_serpent_makekey, alg_serpent_decrypt } },
+#define ALIAS(alias,name,NAME) \
+ { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx), \
+ NAME##_MIN_KEY_SIZE, NAME##_MAX_KEY_SIZE, \
+ 0, \
+ { alg_##name##_makekey, alg_##name##_encr }, \
+ { alg_##name##_makekey, alg_##name##_decr } \
+ },
+#define DO(name,NAME) ALIAS(name,name,NAME)
+ NETTLE_BLOCKCIPHERS
+#undef DO
+#undef ALIAS
+ { 0 }
+};
+
+const BlockCipherPropInfo blockcipherpropinfos[]= {
+ { "blocklen", offsetof(BlockCipherAlgInfo, blocksize) },
+ { "minkeylen", offsetof(BlockCipherAlgInfo, key_min) },
+ { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max) },
{ 0 }
};
NETTLE_DIGESTS
#undef DO
+const HashAlgPropInfo hashalgpropinfos[]= {
+ { "hashlen", offsetof(HashAlgInfo, hashsize) },
+ { "blocklen", offsetof(HashAlgInfo, blocksize) },
+ { 0 }
+};
+
const HashAlgInfo hashalginfos[]= {
#define DO(name,NAME) \
{ #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
const void *sch) {
int blocksize= alg->blocksize;
memcpy(chain,iv,blocksize);
- alg->byteswap(chain);
+ if (alg->byteswap) alg->byteswap(chain);
while (blocks > 0) {
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
memxor(data, chain, blocksize);
alg->encrypt.crypt(sch, data, data);
memcpy(chain, data, blocksize);
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
blocks--; data += blocksize;
}
return 0;
int cchain= 0;
memcpy(chain,iv,blocksize);
- alg->byteswap(chain);
+ if (alg->byteswap) alg->byteswap(chain);
while (blocks > 0) {
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
memcpy(chain + (cchain^blocksize), data, blocksize);
alg->decrypt.crypt(sch, data, data);
memxor(data, chain + cchain, blocksize);
cchain ^= blocksize;
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
blocks--; data += blocksize;
}
return 0;
int blocksize= alg->blocksize;
memcpy(buf,iv,blocksize);
- alg->byteswap(buf);
+ if (alg->byteswap) alg->byteswap(buf);
while (blocks > 0) {
memcpy(buf + blocksize, data, blocksize);
- alg->byteswap(buf + blocksize);
+ if (alg->byteswap) alg->byteswap(buf + blocksize);
memxor(buf, buf + blocksize, blocksize);
alg->encrypt.crypt(sch, buf, buf);
const BlockCipherAlgInfo *alg,
const void *sch) {
cbcmac_core(data,blocks,iv,buf,alg,sch);
- alg->byteswap(buf);
+ if (alg->byteswap) alg->byteswap(buf);
return 0;
}
const void *sch) {
cbcmac_core(data,blocks,iv,buf,alg,sch);
alg->encrypt.crypt(sch, buf, buf);
- alg->byteswap(buf);
+ if (alg->byteswap) alg->byteswap(buf);
return 0;
}
int blocksize= alg->blocksize;
while (blocks > 0) {
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
(encr ? &alg->encrypt : &alg->decrypt)->crypt(sch, data, data);
- alg->byteswap(data);
+ if (alg->byteswap) alg->byteswap(data);
blocks--; data += blocksize;
}
return 0;
return TCL_OK;
}
+
+int do_blockcipherop_prop(ClientData cd, Tcl_Interp *ip,
+ const BlockCipherPropInfo *prop,
+ const BlockCipherAlgInfo *alg, int *result) {
+ *result= *(const int*)((const char*)alg + prop->int_offset);
+ return TCL_OK;
+}
+
+int do_hbytes_hash_prop(ClientData cd, Tcl_Interp *ip,
+ const HashAlgPropInfo *prop,
+ const HashAlgInfo *alg, int *result) {
+ *result= *(const int*)((const char*)alg + prop->int_offset);
+ return TCL_OK;
+}
* hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p)
* hbytes blockcipher d|e VAR ALG KEY MODE [IV] => IV
* hbytes blockcipher mac MSG ALG KEY MODE IV => final block
+ * hbytes blockcipher prop PROPERTY ALG => property value
*
* hbytes hash ALG MESSAGE => hash
* hbytes hmac ALG MESSAGE KEY [MACLENGTH] => mac
+ * hbytes hash-prop PROPERTY ALG => property value
*
* ulong ul2int ULONG => INT can fail if >INT_MAX
* ulong int2ul INT => ULONG can fail if <0
/* from algtables.c */
+typedef struct {
+ const char *name;
+ int int_offset;
+} BlockCipherPropInfo, HashAlgPropInfo;
+
typedef struct {
const char *name;
int hashsize, blocksize, statesize;