Eneboo - Documentación para desarrolladores
src/libdigidoc/openssl/crypto/seed/seed_locl.h
Ir a la documentación de este archivo.
00001 /*
00002  * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved.  
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Neither the name of author nor the names of its contributors may
00010  *    be used to endorse or promote products derived from this software
00011  *    without specific prior written permission.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00014  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00016  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
00017  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00018  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00019  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00020  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00021  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00022  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00023  * SUCH DAMAGE.
00024  *
00025  */
00026 #ifndef HEADER_SEED_LOCL_H
00027 #define HEADER_SEED_LOCL_H
00028 
00029 #include "openssl/e_os2.h"
00030 #include <openssl/seed.h>
00031 
00032 
00033 #ifdef SEED_LONG /* need 32-bit type */
00034 typedef unsigned long seed_word;
00035 #else
00036 typedef unsigned int seed_word;
00037 #endif
00038 
00039 
00040 #ifdef  __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 #define G_FUNC(v)       \
00045         SS[0][(unsigned char)      (v) & 0xff] ^ SS[1][(unsigned char) ((v)>>8) & 0xff] ^ \
00046         SS[2][(unsigned char)((v)>>16) & 0xff] ^ SS[3][(unsigned char)((v)>>24) & 0xff]
00047 
00048 #define char2word(c, i)  \
00049         (i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3]))
00050 
00051 #define word2char(l, c)  \
00052         *((c)+0) = (unsigned char)((l)>>24) & 0xff; \
00053         *((c)+1) = (unsigned char)((l)>>16) & 0xff; \
00054         *((c)+2) = (unsigned char)((l)>> 8) & 0xff; \
00055         *((c)+3) = (unsigned char)((l))     & 0xff
00056 
00057 #define KEYSCHEDULE_UPDATE0(T0, T1, X1, X2, X3, X4, KC)  \
00058         (T0) = (X3);                                     \
00059         (X3) = (((X3)<<8) ^ ((X4)>>24)) & 0xffffffff;    \
00060         (X4) = (((X4)<<8) ^ ((T0)>>24)) & 0xffffffff;    \
00061         (T0) = ((X1) + (X3) - (KC))     & 0xffffffff;    \
00062         (T1) = ((X2) + (KC) - (X4))     & 0xffffffff
00063 
00064 #define KEYSCHEDULE_UPDATE1(T0, T1, X1, X2, X3, X4, KC)  \
00065         (T0) = (X1);                                     \
00066         (X1) = (((X1)>>8) ^ ((X2)<<24)) & 0xffffffff;    \
00067         (X2) = (((X2)>>8) ^ ((T0)<<24)) & 0xffffffff;    \
00068         (T0) = ((X1) + (X3) - (KC))     & 0xffffffff;     \
00069         (T1) = ((X2) + (KC) - (X4))     & 0xffffffff
00070 
00071 #define KEYUPDATE_TEMP(T0, T1, K)   \
00072         (K)[0] = G_FUNC((T0));      \
00073         (K)[1] = G_FUNC((T1))
00074 
00075 #define XOR_SEEDBLOCK(DST, SRC)      \
00076         ((DST))[0] ^= ((SRC))[0];    \
00077         ((DST))[1] ^= ((SRC))[1];    \
00078         ((DST))[2] ^= ((SRC))[2];    \
00079         ((DST))[3] ^= ((SRC))[3]
00080 
00081 #define MOV_SEEDBLOCK(DST, SRC)      \
00082         ((DST))[0] = ((SRC))[0];     \
00083         ((DST))[1] = ((SRC))[1];     \
00084         ((DST))[2] = ((SRC))[2];     \
00085         ((DST))[3] = ((SRC))[3]
00086 
00087 # define CHAR2WORD(C, I)              \
00088         char2word((C),    (I)[0]);    \
00089         char2word((C+4),  (I)[1]);    \
00090         char2word((C+8),  (I)[2]);    \
00091         char2word((C+12), (I)[3])
00092 
00093 # define WORD2CHAR(I, C)              \
00094         word2char((I)[0], (C));       \
00095         word2char((I)[1], (C+4));     \
00096         word2char((I)[2], (C+8));     \
00097         word2char((I)[3], (C+12))
00098 
00099 # define E_SEED(T0, T1, X1, X2, X3, X4, rbase)   \
00100         (T0) = (X3) ^ (ks->data)[(rbase)];       \
00101         (T1) = (X4) ^ (ks->data)[(rbase)+1];     \
00102         (T1) ^= (T0);                            \
00103         (T1) = G_FUNC((T1));                     \
00104         (T0) = ((T0) + (T1)) & 0xffffffff;       \
00105         (T0) = G_FUNC((T0));                     \
00106         (T1) = ((T1) + (T0)) & 0xffffffff;       \
00107         (T1) = G_FUNC((T1));                     \
00108         (T0) = ((T0) + (T1)) & 0xffffffff;       \
00109         (X1) ^= (T0);                            \
00110         (X2) ^= (T1)
00111 
00112 #ifdef  __cplusplus
00113 }
00114 #endif
00115 
00116 #endif /* HEADER_SEED_LOCL_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'