+++ /dev/null
-/*\r
- * GPAC - Multimedia Framework C SDK\r
- *\r
- * Copyright (c) Jean Le Feuvre 2000-2005\r
- * All rights reserved\r
- *\r
- * This file is part of GPAC / Crypto Tools sub-project\r
- *\r
- * GPAC is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- * \r
- * GPAC is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Lesser General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; see the file COPYING. If not, write to\r
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
- *\r
- */\r
-\r
-/*\r
- The GPAC crypto lib is a simplified version of libmcrypt - not all algos are included.\r
- Doc here is man mcrypt\r
- Original libmcrypt license\r
-*/\r
-\r
-/*\r
- * Copyright (C) 1998,1999,2000 Nikos Mavroyanopoulos\r
- * \r
- * This library is free software; you can redistribute it and/or modify it \r
- * under the terms of the GNU Library General Public License as published \r
- * by the Free Software Foundation; either version 2 of the License, or \r
- * (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the\r
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#ifndef _GF_CRYPT_H_\r
-#define _GF_CRYPT_H_\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#include <gpac/tools.h>\r
-\r
-/*max number of possible key sizes for all supported modes*/\r
-#define MAX_KEY_SIZES 4\r
-\r
-/*crypto lib handler*/\r
-typedef struct _tag_crypt_stream GF_Crypt;\r
-\r
-/*supported modes (case insensitive): "CBC", "CFB", "CTR", "ECB", "nCFB", "nOFB", "OFB", "STREAM"*/\r
-/*supported algos (case insensitive): \r
- "AES-128" == "Rijndael-128"\r
- "AES-192" == "Rijndael-192"\r
- "AES-256" == "Rijndael-256"\r
- "DES", "3DES"\r
-*/\r
-\r
-\r
-/*opens crypto context - algo and mode SHALL NOT be NULL*/\r
-GF_Crypt *gf_crypt_open(const char *algorithm, const char *mode);\r
-/*close crypto context*/\r
-void gf_crypt_close(GF_Crypt *gfc);\r
-\r
-/* sets the state of the algorithm. Can be used only with block algorithms and certain modes like CBC, CFB etc. \r
-It is usefully if you want to restart or start a different encryption quickly. \r
-*/\r
-GF_Err gf_crypt_set_state(GF_Crypt *gfc, const void *iv, int size);\r
-/*gets the state of the algorithm. Can be used only certain modes and algorithms. \r
-The size will hold the size of the state and the state must have enough bytes to hold it.\r
-*/\r
-GF_Err gf_crypt_get_state(GF_Crypt *gfc, void *iv, int *size);\r
-/*Returns 1 if the algorithm is a block algorithm or 0 if it is a stream algorithm.*/\r
-Bool gf_crypt_is_block_algorithm(GF_Crypt *gfc);\r
-/*Returns 1 if the mode is for use with block algorithms, otherwise it returns 0.*/\r
-Bool gf_crypt_is_block_algorithm_mode(GF_Crypt *gfc);\r
-/*Returns 1 if the mode outputs blocks of bytes or 0 if it outputs bytes. (eg. 1 for cbc and ecb, and 0 for cfb and stream)*/\r
-Bool gf_crypt_is_block_mode(GF_Crypt *gfc);\r
-/*Returns the block size of the algorithm specified by the encryption descriptor in bytes.*/\r
-u32 gf_crypt_get_block_size(GF_Crypt *gfc);\r
-/*Returns the maximum supported key size of the algorithm specified by the encryption descriptor in bytes.*/\r
-u32 gf_crypt_get_key_size(GF_Crypt *gfc);\r
-/*Returns the number of supported key sizes.\r
-@keys: array of at least MAX_KEY_SIZES size - will hold the supported sizes*/\r
-u32 gf_crypt_get_supported_key_sizes(GF_Crypt *gfc, u32 *key_sizes);\r
-/*Returns size (in bytes) of the IV of the algorithm specified for the context. \r
-If it is '0' then the IV is ignored in that algorithm. \r
-IV is used in CBC, CFB, OFB modes, and in some algorithms in STREAM mode.\r
-*/\r
-u32 gf_crypt_get_iv_size(GF_Crypt *gfc);\r
-/*Returns 1 if the mode needs an IV, 0 otherwise. \r
-Some 'stream' algorithms may need an IV even if the mode itself does not need an IV.\r
-*/\r
-Bool gf_crypt_mode_has_iv(GF_Crypt *gfc);\r
-\r
-/*guess what these do...*/\r
-const char *gf_crypt_get_algorithm_name(GF_Crypt *gfc);\r
-u32 gf_crypt_get_algorithm_version(GF_Crypt *gfc);\r
-const char *gf_crypt_get_mode_name(GF_Crypt *gfc);\r
-u32 gf_crypt_get_mode_version(GF_Crypt *gfc);\r
-\r
-\r
-/*\r
-This function initializes all buffers for the specified context\r
-@Lenofkey: key size in BYTES - maximum value of lenofkey should be the one obtained by \r
-calling gf_crypt_get_key_size() and every value smaller than this is legal.\r
-@IV: usually size of the algorithms block size - get it by calling gf_crypt_get_iv_size().\r
- IV is ignored in ECB. IV MUST exist in CFB, CBC, STREAM, nOFB and OFB modes.\r
- It needs to be random and unique (but not secret). The same IV must be used\r
- for encryption/decryption. \r
-After calling this function you can use the descriptor for encryption or decryption (not both). \r
-*/\r
-GF_Err gf_crypt_init(GF_Crypt *gfc, void *key, u32 lenofkey, const void *IV);\r
-/*releases context buffers - you may call gf_crypt_init after that, or gf_crypt_close*/\r
-void gf_crypt_deinit(GF_Crypt *gfc);\r
-/*changes key and IV*/\r
-GF_Err gf_crypt_set_key(GF_Crypt *gfc, void *key, u32 keysize, const void *iv);\r
-\r
-/*\r
-main encryption function. \r
-@Plaintext, @len: plaintext to encrypt - len should be k*algorithms_block_size if used in a mode\r
-which operated in blocks (cbc, ecb, nofb), or whatever when used in cfb or ofb which operate in streams.\r
-The plaintext is replaced by the ciphertext. \r
-*/\r
-GF_Err gf_crypt_encrypt(GF_Crypt *gfc, void *plaintext, int len);\r
-/*decryption function. It is almost the same with gf_crypt_generic.*/\r
-GF_Err gf_crypt_decrypt(GF_Crypt *gfc, void *ciphertext, int len);\r
-\r
-/*various queries on both modes and algo*/\r
-u32 gf_crypt_str_get_algorithm_version(const char *algorithm);\r
-u32 gf_crypt_str_get_mode_version(const char *mode);\r
-Bool gf_crypt_str_is_block_algorithm(const char *algorithm);\r
-Bool gf_crypt_str_is_block_algorithm_mode(const char *algorithm);\r
-Bool gf_crypt_str_is_block_mode(const char *mode);\r
-u32 gf_crypt_str_module_get_algo_block_size(const char *algorithm);\r
-u32 gf_crypt_str_module_get_algo_key_size(const char *algorithm);\r
-u32 gf_crypt_str_get_algo_supported_key_sizes(const char *algorithm, int *keys);\r
-\r
-\r
-\r
-/*SHA1 from Christophe Devine*/\r
-typedef struct\r
-{\r
- u32 total[2];\r
- u32 state[5];\r
- u8 buffer[64];\r
-} GF_SHA1Context;\r
-\r
-/*\r
- * Core SHA-1 functions\r
- */\r
-void gf_sha1_starts(GF_SHA1Context *ctx );\r
-void gf_sha1_update(GF_SHA1Context *ctx, u8 *input, u32 length);\r
-void gf_sha1_finish(GF_SHA1Context *ctx, u8 digest[20] );\r
-\r
-/*\r
- * Output SHA-1(file contents), returns 0 if successful.\r
- */\r
-int gf_sha1_file(char *filename, u8 digest[20]);\r
-\r
-/*\r
- * Output SHA-1(buf)\r
- */\r
-void gf_sha1_csum(u8 *buf, u32 buflen, u8 digest[20]);\r
-\r
-/*\r
- * Output HMAC-SHA-1(key,buf)\r
- */\r
-void gf_sha1_hmac(u8 *key, u32 keylen, u8 *buf, u32 buflen, u8 digest[20]);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif /*_GF_CRYPT_H_*/\r
-\r