[BACK]Return to des3.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_ntl / crypt / des

Annotation of OpenXM/src/ox_ntl/crypt/des/des3.c, Revision 1.1

1.1     ! iwane       1: /* $OpenXM$ */
        !             2: /*
        !             3:  * Triple-DES
        !             4:  *   see des.c
        !             5:  */
        !             6:
        !             7: #include <stdio.h>
        !             8:
        !             9: #include "des3.h"
        !            10: #include "block.h"
        !            11:
        !            12: #ifdef HAVE_CONFIG_H
        !            13: #include "config.h"
        !            14: #endif
        !            15:
        !            16: #define BLOCK 8
        !            17:
        !            18:
        !            19: /*===========================================================*
        !            20:  * KEY STRUCT
        !            21:  *===========================================================*/
        !            22:
        !            23: int
        !            24: des3_keychk(des3_key *key)
        !            25: {
        !            26:        int ret = 1;
        !            27:        int i;
        !            28:
        !            29:        for (i = 0; i < 3; i++) {
        !            30:                ret = (ret && des_keychk(key->key + i));
        !            31:        }
        !            32:
        !            33:        return (ret);
        !            34: }
        !            35:
        !            36: void
        !            37: des3_keyset(const unsigned char *key, des3_key *dkey)
        !            38: {
        !            39:        int i;
        !            40:
        !            41:        for (i = 0; i < 3; i++) {
        !            42:                des_keyset(key + 8 * i, dkey->key + i);
        !            43:        }
        !            44: }
        !            45:
        !            46:
        !            47:
        !            48:
        !            49: /*===========================================================*
        !            50:  * BASE CRYPTO
        !            51:  *===========================================================*/
        !            52: /**
        !            53:  * input: data: 8 byte
        !            54:  */
        !            55: int
        !            56: des3_enc_c(const des3_key *key, const unsigned char *data, unsigned char *enc)
        !            57: {
        !            58:        unsigned char b1[8];
        !            59:        unsigned char b2[8];
        !            60:
        !            61:        des_enc_c(key->key + 0, data, b1);
        !            62:        des_dec_c(key->key + 1, b1, b2);
        !            63:        des_enc_c(key->key + 2, b2, enc);
        !            64:
        !            65:        return (0);
        !            66: }
        !            67:
        !            68:
        !            69: /**
        !            70:  * input: data: 8 byte
        !            71:  */
        !            72: int
        !            73: des3_dec_c(const des3_key *key, const unsigned char *enc, unsigned char *data)
        !            74: {
        !            75:        unsigned char b1[8];
        !            76:        unsigned char b2[8];
        !            77:
        !            78:        des_dec_c(key->key + 0, enc, b1);
        !            79:        des_enc_c(key->key + 1, b1, b2);
        !            80:        des_dec_c(key->key + 2, b2, data);
        !            81:
        !            82:        return (0);
        !            83: }
        !            84:
        !            85: /*===========================================================*
        !            86:  * CRYPTO: length of input data is "64 * n" byte
        !            87:  *===========================================================*/
        !            88: int
        !            89: des3_enc_ecb(const des3_key *key, int len, const unsigned char *data, unsigned char *buf)
        !            90: {
        !            91:        int ret;
        !            92:
        !            93:        ret = crypt_ecb((void *)key, BLOCK, len, data, buf, (void *)des3_enc_c);
        !            94:
        !            95:        return (ret);
        !            96: }
        !            97:
        !            98:
        !            99: int
        !           100: des3_dec_ecb(const des3_key *key, int len, const unsigned char *enc, unsigned char *data)
        !           101: {
        !           102:        int ret;
        !           103:
        !           104:        ret = crypt_ecb((void *)key, BLOCK, len, enc, data, (void *)des3_dec_c);
        !           105:
        !           106:        return (ret);
        !           107: }
        !           108:
        !           109:
        !           110:
        !           111: int
        !           112: des3_enc_cbc(const des3_key *key, const unsigned char *iv, int len,
        !           113:     const unsigned char *data, unsigned char *buf)
        !           114: {
        !           115:        int ret;
        !           116:
        !           117:        ret = crypt_enc_cbc((void *)key, BLOCK, iv, len, data, buf, (void *)des3_enc_c);
        !           118:
        !           119:        return (ret);
        !           120: }
        !           121:
        !           122:
        !           123: int
        !           124: des3_dec_cbc(const des3_key *key, unsigned char *iv, int len,
        !           125:     const unsigned char *data, unsigned char *buf)
        !           126: {
        !           127:        int ret;
        !           128:
        !           129:        ret = crypt_dec_cbc((void *)key, BLOCK, iv, len, data, buf, (void *)des3_dec_c);
        !           130:
        !           131:        return (ret);
        !           132: }
        !           133:
        !           134:
        !           135: int
        !           136: des3_enc_cfb(const des3_key *key, int bit,
        !           137:     const unsigned char *iv, int len,
        !           138:     const unsigned char *data, unsigned char *buf)
        !           139: {
        !           140:        int ret;
        !           141:
        !           142:        ret = crypt_cfb((void *)key, 0, bit, BLOCK, iv, len, data, buf, (void *)des3_enc_c);
        !           143:
        !           144:        return (ret);
        !           145: }
        !           146:
        !           147: int
        !           148: des3_dec_cfb(const des3_key *key, int bit,
        !           149:     const unsigned char *iv, int len,
        !           150:     const unsigned char *data, unsigned char *buf)
        !           151: {
        !           152:        int ret;
        !           153:
        !           154:        ret = crypt_cfb((void *)key, 1, bit, BLOCK, iv, len, data, buf, (void *)des3_enc_c);
        !           155:
        !           156:        return (ret);
        !           157: }
        !           158:
        !           159:
        !           160: int
        !           161: des3_ofb(const des3_key *key, int bit,
        !           162:     const unsigned char *iv, int len,
        !           163:     const unsigned char *data,
        !           164:     unsigned char *buf)
        !           165: {
        !           166:        int ret;
        !           167:        ret = crypt_ofb((void *)key, bit, BLOCK, iv, len, data, buf, (void *)des3_enc_c);
        !           168:
        !           169:        return (ret);
        !           170: }
        !           171:
        !           172:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>