1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: crypto_CtrDecryptor.h 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. 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 $Rev: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_CRYPTO_CRYPTO_CTRDECRYPTOR_H_ 17 #define NN_CRYPTO_CRYPTO_CTRDECRYPTOR_H_ 18 19 #include <nn/crypto/crypto_Decryptor.h> 20 #include <nn/crypto/detail/crypto_CtrMode.h> 21 22 23 namespace nn { 24 namespace crypto { 25 26 27 28 /* Please see man pages for details 29 30 31 32 33 34 35 36 37 38 39 40 41 42 */ 43 template <size_t BlockSize> 44 class CtrDecryptor : public Decryptor 45 { 46 private: 47 typedef detail::CtrMode<BlockSize> ImplT; 48 49 public: 50 // 51 // 52 // 53 static const size_t BLOCK_SIZE = ImplT::BLOCK_SIZE; 54 55 // 56 // 57 // 58 static const size_t IV_SIZE = ImplT::IV_SIZE; 59 60 // 61 // 62 // 63 static const size_t UNIT_SIZE = ImplT::UNIT_SIZE; 64 65 public: CtrDecryptor()66 CtrDecryptor(){} ~CtrDecryptor()67 virtual ~CtrDecryptor(){} 68 69 /* Please see man pages for details 70 71 72 73 74 75 76 */ GetIvSize()77 virtual size_t GetIvSize() const { return ImplT::GetIvSize(); } 78 79 /* Please see man pages for details 80 81 82 83 84 85 */ GetUnitSize()86 virtual size_t GetUnitSize() const { return ImplT::GetUnitSize(); } 87 88 89 90 /* Please see man pages for details 91 92 93 94 95 96 97 98 */ Initialize(const BlockCipher & c,const void * pIv,size_t ivSize)99 virtual void Initialize(const BlockCipher& c, const void* pIv, size_t ivSize) 100 { return m_Impl.Initialize(c, pIv, ivSize); } 101 102 /* Please see man pages for details 103 104 105 106 */ Finalize()107 virtual void Finalize() 108 { return m_Impl.Finalize(); } 109 110 /* Please see man pages for details 111 112 113 114 115 116 117 118 119 120 */ Update(void * pDst,size_t dstSize,const void * pSrc,size_t srcSize)121 virtual size_t Update(void* pDst, size_t dstSize, const void* pSrc, size_t srcSize) 122 { return m_Impl.Update(pDst, dstSize, pSrc, srcSize); } 123 124 /* Please see man pages for details 125 126 127 128 129 130 131 132 */ UpdateFinal(void * pDst,size_t size)133 virtual size_t UpdateFinal(void* pDst, size_t size) 134 { return m_Impl.UpdateFinal(pDst, size); } 135 136 137 138 /* Please see man pages for details 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 */ Decrypt(void * pDst,size_t dstSize,const void * pSrc,size_t srcSize,const void * pIv,size_t ivSize,const BlockCipher & c)168 static size_t Decrypt(void* pDst, size_t dstSize, const void* pSrc, size_t srcSize, 169 const void* pIv, size_t ivSize, const BlockCipher& c) 170 { 171 CtrDecryptor<BlockSize> e; 172 return e.Decryptor::Decrypt(pDst, dstSize, pSrc, srcSize, pIv, ivSize, c); 173 } 174 175 private: 176 ImplT m_Impl; 177 }; 178 179 /* Please see man pages for details 180 181 */ 182 typedef CtrDecryptor<16> CtrDecryptor128; 183 184 185 186 } // namespace crypto 187 } // namespace nn 188 189 190 191 #endif /* NN_CRYPTO_CRYPTO_CTRDECRYPTOR_H_ */ 192