00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
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
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
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
00138 void ivec_inc(unsigned char *counter);
00139
00140
00147
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 }
00330 #endif
00331