/*---------------------------------------------------------------------------* Project: Horizon File: crypto_HashContextBase.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 12449 $ *---------------------------------------------------------------------------*/ #ifndef NN_CRYPTO_CRYPTO_HASHCONTEXTBASE_H_ #define NN_CRYPTO_CRYPTO_HASHCONTEXTBASE_H_ #include #include #ifdef __cplusplus namespace nn{ namespace crypto{ /*! @brief Hash 計算用コンテキストオブジェクトの基底クラスです。 このクラスを直接インスタンス化することはできません。 継承先のクラスを使用してください。 */ class HashContextBase { public: /* @brief オブジェクトの初期化処理 @return 無し。 */ virtual void Initialize() {} /* @brief オブジェクトの完了処理 @return 無し。 */ virtual void Finalize() {} /* @brief ハッシュ/ダイジェスト値を与えられたデータで更新します。 @return 無し。 */ virtual void Update(const void* pData, size_t length) { NN_UNUSED_VAR(pData); NN_UNUSED_VAR(length); } /* @brief ハッシュ/ダイジェストの長さを取得します。 @return ハッシュ/ダイジェストの長さ。 */ virtual size_t GetHashLength() { return 0; } /* @brief 最終的なハッシュ/ダイジェスト計算結果を取得します。 @return 無し。 */ virtual void GetHash(void* pOut) { NN_UNUSED_VAR(pOut); } protected: // 単独インスタンス化の禁止 HashContextBase() {} ~HashContextBase() {} // 内部ブロック処理 virtual void ProcessBlock() {} // 必要内部関数 inline static u32 RotateLeft32(int shift, u32 value) { return (u32)((value << shift) | (value >> (u32)(32 - shift))); } inline static u32 Convert32HToBE( u32 val ) { #if NN_ENDIAN == NN_ENDIAN_VALUE_LITTLE return (u32)( (((val) >> 24UL) & 0x000000FFUL) | (((val) >> 8UL) & 0x0000FF00UL) | (((val) << 8UL) & 0x00FF0000UL) | (((val) << 24UL) & 0xFF000000UL) ); #else return val; #endif } inline static void FillBytes(u8* pDst, u8 data, size_t length) { for ( s32 i = 0 ; i < length ; ++i ) { *pDst++ = data; } } inline static void CopyBytes(const u8* pSrc, u8* pDst, size_t length) { for ( s32 i = 0 ; i < length ; ++i ) { *pDst++ = *pSrc++; } } private: }; }} // namespace nn::crypto #endif // __cplusplus #endif /* NN_CRYPTO_CRYPTO_HASHCONTEXTBASE_H_ */