00001
#ifndef CRYPTOPP_PANAMA_H
00002
#define CRYPTOPP_PANAMA_H
00003
00004
#include "seckey.h"
00005
#include "secblock.h"
00006
#include "iterhash.h"
00007
#include "strciphr.h"
00008
00009 NAMESPACE_BEGIN(CryptoPP)
00010
00011
00012 template <class B>
00013 class
Panama
00014 {
00015
public:
00016
void Reset();
00017
void Iterate(
unsigned int count,
const word32 *p=NULL, word32 *z=NULL,
const word32 *y=NULL);
00018
00019
protected:
00020
typedef word32 Stage[8];
00021
enum {STAGES = 32};
00022
00023 FixedSizeSecBlock<word32, 17*2 + STAGES*sizeof(Stage)> m_state;
00024
unsigned int m_bstart;
00025 };
00026
00027
00028
template <
class B = LittleEndian>
00029 class PanamaHash :
protected Panama<B>,
public IteratedHash<word32, NativeByteOrder, 32>
00030 {
00031
public:
00032
enum {DIGESTSIZE = 32};
00033
PanamaHash() :
IteratedHash<word32, NativeByteOrder, 32>(0) {
Panama<B>::Reset();}
00034
unsigned int DigestSize()
const {
return DIGESTSIZE;}
00035
void TruncatedFinal(byte *hash,
unsigned int size);
00036
00037
protected:
00038
void Init() {
Panama<B>::Reset();}
00039
void vTransform(
const word32 *data) {Iterate(1, data);}
00040
unsigned int HashMultipleBlocks(
const word32 *input,
unsigned int length);
00041 };
00042
00043
00044
template <
class B = LittleEndian>
00045 class PanamaMAC_Base :
public PanamaHash<B>,
public VariableKeyLength<32, 0, UINT_MAX>,
public MessageAuthenticationCode
00046 {
00047
public:
00048
void UncheckedSetKey(
const byte *userKey,
unsigned int keylength)
00049 {
00050 m_key.
Assign(userKey, keylength);
00051
Restart();
00052 }
00053
00054
static const char * StaticAlgorithmName() {
return B::ToEnum() == BIG_ENDIAN ?
"Panama-BE" :
"Panama-LE";}
00055
00056
protected:
00057
void Init()
00058 {
00059
PanamaHash<B>::Init();
00060 Update(m_key, m_key.
size());
00061 }
00062
00063
SecByteBlock m_key;
00064 };
00065
00066
00067
template <
class B = LittleEndian>
00068 class PanamaMAC :
public MessageAuthenticationCodeTemplate<PanamaMAC_Base<B> >
00069 {
00070
public:
00071
PanamaMAC() {}
00072
PanamaMAC(
const byte *key,
unsigned int length=
PanamaMAC_Base<B>::DEFAULT_KEYLENGTH)
00073 {SetKey(key, length);}
00074 };
00075
00076
00077
template <
class B>
00078 struct PanamaCipherInfo :
public VariableKeyLength<32, 32, 64, 32, SimpleKeyingInterface::NOT_RESYNCHRONIZABLE>
00079 {
00080
static const char * StaticAlgorithmName() {
return B::ToEnum() == BIG_ENDIAN_ORDER ?
"Panama-BE" :
"Panama-LE";}
00081 };
00082
00083
00084
template <
class B>
00085 class PanamaCipherPolicy :
public AdditiveCipherConcretePolicy<word32, 32>,
00086
public PanamaCipherInfo<B>,
00087
protected Panama<B>
00088 {
00089
protected:
00090
void CipherSetKey(
const NameValuePairs ¶ms,
const byte *key,
unsigned int length);
00091
void OperateKeystream(KeystreamOperation operation, byte *output,
const byte *input,
unsigned int iterationCount);
00092
bool IsRandomAccess()
const {
return false;}
00093 };
00094
00095
00096
template <
class B = LittleEndian>
00097 struct PanamaCipher :
public PanamaCipherInfo<B>,
public SymmetricCipherDocumentation
00098 {
00099 typedef SymmetricCipherFinalTemplate<ConcretePolicyHolder<PanamaCipherPolicy<B>, AdditiveCipherTemplate<> > >
Encryption;
00100 typedef Encryption Decryption;
00101 };
00102
00103 NAMESPACE_END
00104
00105
#endif