rijndael-api-fst.h
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:5k
源码类别:

DVD

开发平台:

Others

  1. /**
  2.  * rijndael-api-fst.h
  3.  *
  4.  * @version 2.9 (December 2000)
  5.  *
  6.  * Optimised ANSI C code for the Rijndael cipher (now AES)
  7.  *
  8.  * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
  9.  * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
  10.  * @author Paulo Barreto <paulo.barreto@terra.com.br>
  11.  *
  12.  * This code is hereby placed in the public domain.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
  15.  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
  18.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  24.  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  *
  26.  * Acknowledgements:
  27.  *
  28.  * We are deeply indebted to the following people for their bug reports,
  29.  * fixes, and improvement suggestions to this implementation. Though we
  30.  * tried to list all contributions, we apologise in advance for any
  31.  * missing reference.
  32.  *
  33.  * Andrew Bales <Andrew.Bales@Honeywell.com>
  34.  * Markus Friedl <markus.friedl@informatik.uni-erlangen.de>
  35.  * John Skodon <skodonj@webquill.com>
  36.  */
  37. #ifndef __RIJNDAEL_API_FST_H
  38. #define __RIJNDAEL_API_FST_H
  39. #include "Config.h" // Global Configuration - do not remove!
  40. #include "Includesysdefs.h"
  41. #ifdef AVI_DRM_SUPPORT
  42. #include <stdio.h>
  43. #include "PlaycoreNav_ClipsAviDrmlibAESrijndael-alg-fst.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /*  Generic Defines  */
  48. #define     DIR_ENCRYPT           0 /*  Are we encrpyting?  */
  49. #define     DIR_DECRYPT           1 /*  Are we decrpyting?  */
  50. #define     MODE_ECB              1 /*  Are we ciphering in ECB mode?   */
  51. #define     MODE_CBC              2 /*  Are we ciphering in CBC mode?   */
  52. #define     MODE_CFB1             3 /*  Are we ciphering in 1-bit CFB mode? */
  53. #define     TRUE                  1
  54. #define     FALSE                 0
  55. #define     BITSPERBLOCK        128 /* Default number of bits in a cipher block */
  56. /*  Error Codes  */
  57. #define     BAD_KEY_DIR          -1 /*  Key direction is invalid, e.g., unknown value */
  58. #define     BAD_KEY_MAT          -2 /*  Key material not of correct length */
  59. #define     BAD_KEY_INSTANCE     -3 /*  Key passed is not valid */
  60. #define     BAD_CIPHER_MODE      -4 /*  Params struct passed to cipherInit invalid */
  61. #define     BAD_CIPHER_STATE     -5 /*  Cipher in wrong state (e.g., not initialized) */
  62. #define     BAD_BLOCK_LENGTH     -6
  63. #define     BAD_CIPHER_INSTANCE  -7
  64. #define     BAD_DATA             -8 /*  Data contents are invalid, e.g., invalid padding */
  65. #define     BAD_OTHER            -9 /*  Unknown error */
  66. /*  Algorithm-specific Defines  */
  67. #define     MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
  68. #define     MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
  69. /*  Typedefs  */
  70. typedef unsigned char   BYTE;
  71. /*  The structure for key information */
  72. typedef struct {
  73.     BYTE  direction;                /* Key used for encrypting or decrypting? */
  74.     int   keyLen;                   /* Length of the key  */
  75.     char  keyMaterial[MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
  76. int   Nr;                       /* key-length-dependent number of rounds */
  77. u32   rk[4*(MAXNR + 1)];        /* key schedule */
  78. u32   ek[4*(MAXNR + 1)];        /* CFB1 key schedule (encryption only) */
  79. } keyInstance;
  80. /*  The structure for cipher information */
  81. typedef struct {                    /* changed order of the components */
  82.     BYTE  mode;                     /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
  83.     BYTE  IV[MAX_IV_SIZE];          /* A possible Initialization Vector for ciphering */
  84. } cipherInstance;
  85. /*  Function prototypes  */
  86. int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial);
  87. int cipherInit(cipherInstance *cipher, BYTE mode, char *IV);
  88. int blockEncrypt(cipherInstance *cipher, keyInstance *key,
  89.         BYTE *input, int inputLen, BYTE *outBuffer);
  90. // <<< Robin_0915_2004
  91. #ifndef AVI_DRM_OPTIMIZATION
  92. int padEncrypt(cipherInstance *cipher, keyInstance *key,
  93. BYTE *input, int inputOctets, BYTE *outBuffer);
  94. #endif
  95. // >>> Robin_0915_2004
  96. int blockDecrypt(cipherInstance *cipher, keyInstance *key,
  97.         BYTE *input, int inputLen, BYTE *outBuffer);
  98. int padDecrypt(cipherInstance *cipher, keyInstance *key,
  99. BYTE *input, int inputOctets, BYTE *outBuffer);
  100. #ifdef INTERMEDIATE_VALUE_KAT
  101. int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key,
  102.         BYTE *input, int inputLen, BYTE *outBuffer, int Rounds);
  103. #endif /* INTERMEDIATE_VALUE_KAT */
  104. #ifdef __cplusplus
  105. };
  106. #endif
  107. #endif // AVI_DRM_SUPPORT
  108. #endif /* __RIJNDAEL_API_FST_H */