1 /*---------------------------------------------------------------------------* 2 Project: NitroSDK - CRYPTO - demos 3 File: rc4enc.h 4 5 Copyright 2006 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Log: rc4enc.h,v $ 14 Revision 1.3 2006/03/08 09:15:35 seiki_masashi 15 Revised comments 16 17 Revision 1.2 2006/03/08 09:14:44 seiki_masashi 18 Revised comments 19 20 Revision 1.1 2006/03/08 08:53:41 seiki_masashi 21 Added rc4-3 demo 22 23 $NoKeywords: $ 24 *---------------------------------------------------------------------------*/ 25 26 #ifndef RC4ENC_H_ 27 #define RC4ENC_H_ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /*===========================================================================*/ 34 35 #include <nitro/types.h> 36 37 #define RC4ENC_USER_KEY_LENGTH 12 // Key length specified by user 38 #define RC4ENC_TOTAL_KEY_LENGTH 16 // Final key length 39 40 // Size required when adding during encoding (24 bytes) 41 #define RC4ENC_ADDITIONAL_SIZE (sizeof(u32) /* iv */ + MATH_SHA1_DIGEST_SIZE /* message digest */) 42 43 /*---------------------------------------------------------------------------* 44 Structure Definitions 45 *---------------------------------------------------------------------------*/ 46 typedef struct RC4EncoderContext 47 { 48 CRYPTORC4Context rc4_context; 49 u8 key[RC4ENC_TOTAL_KEY_LENGTH]; 50 } RC4EncoderContext; 51 52 typedef struct RC4DecoderContext 53 { 54 CRYPTORC4Context rc4_context; 55 u8 key[RC4ENC_TOTAL_KEY_LENGTH]; 56 } RC4DecoderContext; 57 58 /*---------------------------------------------------------------------------* 59 function definitions 60 *---------------------------------------------------------------------------*/ 61 /*---------------------------------------------------------------------------* 62 Name: InitRC4Encoder 63 64 Description: This function performs initialization for encryption using the RC4 algorithm. 65 66 Arguments: context - the context structure where the RC4 key information, etc., is kept 67 key - 12-byte key data 68 69 Returns: None. 70 *---------------------------------------------------------------------------*/ 71 void InitRC4Encoder( 72 RC4EncoderContext* context, 73 const void* key 74 ); 75 76 /*---------------------------------------------------------------------------* 77 Name: EncodeRC4 78 79 Description: Performs encryption using the RC4 algorithm. 80 81 Arguments: context - the context structure where the RC4 key information, etc., is to be kept 82 in - input data 83 in_len - Data length 84 out - output data 85 out_len - Size of memory secured as an ouptut buffer 86 87 Returns: Returns the output length if successful; otherwise, returns 0. 88 *---------------------------------------------------------------------------*/ 89 u32 EncodeRC4( 90 RC4EncoderContext* context, 91 const void* in, 92 u32 in_len, 93 void* out, 94 u32 out_len 95 ); 96 97 /*---------------------------------------------------------------------------* 98 Name: InitRC4Decoder 99 100 Description: Performs initialization for decryption using the RC4 algorithm. 101 102 Arguments: context - the context structure where the RC4 key information, etc., is kept 103 key - 12-byte key data 104 105 Returns: None. 106 *---------------------------------------------------------------------------*/ 107 void InitRC4Decoder( 108 RC4DecoderContext* context, 109 const void* key 110 ); 111 112 /*---------------------------------------------------------------------------* 113 Name: DecodeRC4 114 115 Description: Performs decryption using the RC4 algorithm. 116 Modification check of data is also performed. Fails if data has been altered. 117 118 Arguments: context - the context structure where the RC4 key information, etc., is to be kept 119 in - input data 120 in_len - Data length 121 out - output data 122 out_len - Size of memory allocated as an ouptut buffer 123 124 Returns: Returns the output length if successful; otherwise, returns 0. 125 *---------------------------------------------------------------------------*/ 126 u32 DecodeRC4( 127 RC4DecoderContext* context, 128 const void* in, 129 u32 in_len, 130 void* out, 131 u32 out_len 132 ); 133 134 135 /*===========================================================================*/ 136 137 #ifdef __cplusplus 138 } /* extern "C" */ 139 #endif 140 141 #endif /* RC4ENC_H_ */ 142 143 /*---------------------------------------------------------------------------* 144 End of file 145 *---------------------------------------------------------------------------*/ 146