Eneboo - Documentación para desarrolladores
src/libdigidoc/openssl/crypto/camellia/cmll_locl.h
Ir a la documentación de este archivo.
00001 /* crypto/camellia/camellia_locl.h -*- mode:C; c-file-style: "eay" -*- */
00002 /* ====================================================================
00003  * Copyright 2006 NTT (Nippon Telegraph and Telephone Corporation) . 
00004  * ALL RIGHTS RESERVED.
00005  *
00006  * Intellectual Property information for Camellia:
00007  *     http://info.isl.ntt.co.jp/crypt/eng/info/chiteki.html
00008  *
00009  * News Release for Announcement of Camellia open source:
00010  *     http://www.ntt.co.jp/news/news06e/0604/060413a.html
00011  *
00012  * The Camellia Code included herein is developed by
00013  * NTT (Nippon Telegraph and Telephone Corporation), and is contributed
00014  * to the OpenSSL project.
00015  *
00016  * The Camellia Code is licensed pursuant to the OpenSSL open source
00017  * license provided below.
00018  */
00019 /* ====================================================================
00020  * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
00021  *
00022  * Redistribution and use in source and binary forms, with or without
00023  * modification, are permitted provided that the following conditions
00024  * are met:
00025  *
00026  * 1. Redistributions of source code must retain the above copyright
00027  *    notice, this list of conditions and the following disclaimer. 
00028  *
00029  * 2. Redistributions in binary form must reproduce the above copyright
00030  *    notice, this list of conditions and the following disclaimer in
00031  *    the documentation and/or other materials provided with the
00032  *    distribution.
00033  *
00034  * 3. All advertising materials mentioning features or use of this
00035  *    software must display the following acknowledgment:
00036  *    "This product includes software developed by the OpenSSL Project
00037  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
00038  *
00039  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00040  *    endorse or promote products derived from this software without
00041  *    prior written permission. For written permission, please contact
00042  *    openssl-core@openssl.org.
00043  *
00044  * 5. Products derived from this software may not be called "OpenSSL"
00045  *    nor may "OpenSSL" appear in their names without prior written
00046  *    permission of the OpenSSL Project.
00047  *
00048  * 6. Redistributions of any form whatsoever must retain the following
00049  *    acknowledgment:
00050  *    "This product includes software developed by the OpenSSL Project
00051  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
00052  *
00053  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00054  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00055  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00056  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00057  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00058  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00059  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00060  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00061  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00062  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00063  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00064  * OF THE POSSIBILITY OF SUCH DAMAGE.
00065  * ====================================================================
00066  */
00067 
00068 #ifndef HEADER_CAMELLIA_LOCL_H
00069 #define HEADER_CAMELLIA_LOCL_H
00070 
00071 #include "openssl/e_os2.h"
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <string.h>
00075 
00076 typedef unsigned char u8;
00077 typedef unsigned int u32;
00078 
00079 #ifdef __cplusplus
00080 extern "C" {
00081 #endif
00082 
00083 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
00084 # define SWAP(x) ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00 )
00085 # define GETU32(p) SWAP(*((u32 *)(p)))
00086 # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
00087 # define CAMELLIA_SWAP4(x) (x = ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) )
00088 
00089 #else /* not windows */
00090 # define GETU32(pt) (((u32)(pt)[0] << 24) \
00091         ^ ((u32)(pt)[1] << 16) \
00092         ^ ((u32)(pt)[2] <<  8) \
00093         ^ ((u32)(pt)[3]))
00094 
00095 # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
00096         (ct)[1] = (u8)((st) >> 16); \
00097         (ct)[2] = (u8)((st) >>  8); \
00098         (ct)[3] = (u8)(st); }
00099 
00100 #if (defined (__GNUC__) && (defined(__x86_64__) || defined(__x86_64)))
00101 #define CAMELLIA_SWAP4(x) \
00102   do{\
00103     asm("bswap %1" : "+r" (x));\
00104   }while(0)
00105 #else
00106 #define CAMELLIA_SWAP4(x) \
00107    do{\
00108      x = ((u32)x << 16) + ((u32)x >> 16);\
00109      x = (((u32)x & 0xff00ff) << 8) + (((u32)x >> 8) & 0xff00ff);\
00110    } while(0)
00111 #endif
00112 #endif
00113 
00114 #define COPY4WORD(dst, src)      \
00115              do                  \
00116                      {           \
00117                      (dst)[0]=(src)[0];         \
00118                      (dst)[1]=(src)[1];         \
00119                      (dst)[2]=(src)[2];         \
00120                      (dst)[3]=(src)[3];         \
00121                      }while(0)
00122 
00123 #define SWAP4WORD(word)                         \
00124    do                                           \
00125            {                                    \
00126            CAMELLIA_SWAP4((word)[0]);                   \
00127            CAMELLIA_SWAP4((word)[1]);                   \
00128            CAMELLIA_SWAP4((word)[2]);                   \
00129            CAMELLIA_SWAP4((word)[3]);                   \
00130            }while(0)
00131 
00132 #define XOR4WORD(a, b)/* a = a ^ b */           \
00133    do                                           \
00134         {                                       \
00135         (a)[0]^=(b)[0];                         \
00136         (a)[1]^=(b)[1];                         \
00137         (a)[2]^=(b)[2];                         \
00138         (a)[3]^=(b)[3];                         \
00139         }while(0)
00140 
00141 #define XOR4WORD2(a, b, c)/* a = b ^ c */       \
00142    do                                           \
00143         {                                       \
00144         (a)[0]=(b)[0]^(c)[0];                   \
00145         (a)[1]=(b)[1]^(c)[1];                           \
00146         (a)[2]=(b)[2]^(c)[2];                           \
00147         (a)[3]=(b)[3]^(c)[3];                           \
00148         }while(0)
00149 
00150 
00151 void camellia_setup128(const u8 *key, u32 *subkey);
00152 void camellia_setup192(const u8 *key, u32 *subkey);
00153 void camellia_setup256(const u8 *key, u32 *subkey);
00154 
00155 void camellia_encrypt128(const u32 *subkey, u32 *io);
00156 void camellia_decrypt128(const u32 *subkey, u32 *io);
00157 void camellia_encrypt256(const u32 *subkey, u32 *io);
00158 void camellia_decrypt256(const u32 *subkey, u32 *io);
00159 
00160 #ifdef __cplusplus
00161 }
00162 #endif
00163 
00164 #endif /* #ifndef HEADER_CAMELLIA_LOCL_H */
00165 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'