Main Page | Data Structures | File List | Data Fields | Globals

ss-util.h

Go to the documentation of this file.
00001 
00008 /* ss-util.h - Secure Storage utility function header file
00009  * ====================================================================
00010  * Copyright (c) Giordano Scuderi, Unico SRL.  All rights reserved.
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions
00014  * are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  *    notice, this list of conditions and the following disclaimer. 
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright
00020  *    notice, this list of conditions and the following disclaimer in
00021  *    the documentation and/or other materials provided with the
00022  *    distribution.
00023  *
00024  * 3. All advertising materials mentioning features or use of this
00025  *    software must display the following acknowledgment:
00026  *    "This product includes software developed by Giordano Scuderi
00027  *    for Unico SRL"
00028  *
00029  * 4. The names "Secure Storage" must not be used to
00030  *    endorse or promote products derived from this software without
00031  *    prior written permission. For written permission, please contact
00032  *    gscuderi@unicosrl.it.
00033  *
00034  * 5. Products derived from this software may not be called "Secure Storage"
00035  *    nor may "Secure Storage" appear in their names without prior written
00036  *    permission of Giordano Scuderi (Unico SRL).
00037  *
00038  * 6. Redistributions of any form whatsoever must retain the following
00039  *    acknowledgment:
00040  *    "This product includes software developed by Giordano Scuderi
00041  *    for Unico SRL"
00042  *
00043  * THIS SOFTWARE IS PROVIDED BY UNICO SRL ``AS IS'' AND ANY
00044  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00045  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00046  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNICO SRL OR
00047  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00048  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00049  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00050  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00051  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00052  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00053  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00054  * OF THE POSSIBILITY OF SUCH DAMAGE.
00055  * ====================================================================
00056  *
00057  * "This product includes software developed by the OpenSSL Project
00058  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
00059  * 
00060  */
00061 
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065 
00066 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
00067 # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
00068 # define GETU32(p) SWAP(*((u32 *)(p)))
00069 # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
00070 #else
00071 # define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
00072 # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
00073 #endif
00074 
00075 #ifdef AES_LONG
00076 typedef unsigned long u32;
00077 #else
00078 typedef unsigned int u32;
00079 #endif
00080 typedef unsigned short u16;
00081 typedef unsigned char u8;
00082 
00083 #define MAXKC   (256/32)
00084 #define MAXKB   (256/8)
00085 #define MAXNR   14
00086 
00087 /* This controls loop-unrolling in aes_core.c */
00088 #undef FULL_UNROLL
00089 
00090 #define AES_BLOCK_SIZE 16
00091 #define AES_MAXNR 14
00092 #define KEYSIZE 16
00093 #define HEX_KEYSIZE 32
00094 #define IVSIZE 8
00095 #define HEX_IVSIZE 16
00096 
00097 // \struct This struct is used by AES encryption
00098 struct aes_key_st {
00099 #ifdef AES_LONG
00100     unsigned long rd_key[4 *(AES_MAXNR + 1)];
00101 #else
00102     unsigned int rd_key[4 *(AES_MAXNR + 1)];
00103 #endif
00104     int rounds;
00105 };
00106 typedef struct aes_key_st AES_KEY;
00107 
00108 
00117  size_t lock_memory(char *addr, size_t size);
00118 
00119 
00128  size_t unlock_memory(char *addr, size_t size);
00129 
00130 
00137 //static 
00138 void ivec_inc(unsigned char *counter);
00139 
00140 
00147 //static 
00148 void ivec_dec(unsigned char *counter);
00149 
00150 
00175 void securestorage_AES_ctr(const unsigned char *in, unsigned char *out,
00176         const unsigned long length, const AES_KEY *key,
00177         unsigned char ivec[AES_BLOCK_SIZE],
00178         unsigned char ecount_buf[AES_BLOCK_SIZE],
00179         unsigned int *num);
00180         
00181 
00192  int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
00193                         AES_KEY *key);
00194                         
00195 
00207  int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
00208                          AES_KEY *key);
00209                          
00210 
00221  void AES_encrypt(const unsigned char *in, unsigned char *out,
00222                  const AES_KEY *key);
00223                  
00224 
00236  void AES_decrypt(const unsigned char *in, unsigned char *out,
00237                  const AES_KEY *key);
00238  
00239 
00254  int ss_rand (int size, unsigned char *out);
00255  
00256  
00270  int ss_generate_surl (char **dest_surl, char *dest_file, char *vo, char *guid);
00271  
00272 
00284  int ss_get_lfchome ( const char *input_lfn, char **lfn_new );
00285 
00286 
00300  int ss_get_surl ( char *lfn, char **surl, char *vo, char *se, int insecure );
00301 
00302 
00313  int ss_check_lfn ( char *lfn, char *vo);
00314 
00315 
00325 const char *securestorage_error(int errnum);
00326 
00327 
00328 #ifdef __cplusplus
00329 } /* closing brace for extern "C" */
00330 #endif           
00331 

Generated on Wed May 30 09:56:30 2007 for Secure Storage Service by doxygen 1.3.5