~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to des.cpp

  • Committer: weidai
  • Date: 2007-05-04 15:36:15 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:339
fix compile

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
        left = rotrFixed(left^work, 4U);
118
118
}
119
119
 
 
120
void DES::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
 
121
{
 
122
        AssertValidKeyLength(length);
 
123
 
 
124
        RawSetKey(GetCipherDirection(), userKey);
 
125
}
 
126
 
120
127
#ifndef CRYPTOPP_IMPORTS
121
128
 
122
129
/* Tables defined in the Data Encryption Standard documents
264
271
};
265
272
 
266
273
/* Set key (initialize key schedule array) */
267
 
void RawDES::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
 
274
void RawDES::RawSetKey(CipherDir dir, const byte *key)
268
275
{
269
276
        SecByteBlock buffer(56+56+8);
270
277
        byte *const pc1m=buffer;                 /* place to modify pc1 into */
345
352
        l_ = l; r_ = r;
346
353
}
347
354
 
348
 
void DES_EDE2::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
 
355
void DES_EDE2::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
349
356
{
350
357
        AssertValidKeyLength(length);
351
358
 
352
 
        m_des1.UncheckedSetKey(dir, key);
353
 
        m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
 
359
        m_des1.RawSetKey(GetCipherDirection(), userKey);
 
360
        m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey+8);
354
361
}
355
362
 
356
363
void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
365
372
        Block::Put(xorBlock, outBlock)(r)(l);
366
373
}
367
374
 
368
 
void DES_EDE3::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
 
375
void DES_EDE3::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
369
376
{
370
377
        AssertValidKeyLength(length);
371
378
 
372
 
        m_des1.UncheckedSetKey(dir, key+(dir==ENCRYPTION?0:2*8));
373
 
        m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
374
 
        m_des3.UncheckedSetKey(dir, key+(dir==DECRYPTION?0:2*8));
 
379
        m_des1.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 0 : 16));
 
380
        m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey + 8);
 
381
        m_des3.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 16 : 0));
375
382
}
376
383
 
377
384
void DES_EDE3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
420
427
        Block::Put(xorBlock, outBlock)(r)(l);
421
428
}
422
429
 
423
 
void DES_XEX3::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
 
430
void DES_XEX3::Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &)
424
431
{
425
432
        AssertValidKeyLength(length);
426
433
 
427
434
        if (!m_des.get())
428
435
                m_des.reset(new DES::Encryption);
429
436
 
430
 
        memcpy(m_x1, key+(dir==ENCRYPTION?0:2*8), BLOCKSIZE);
431
 
        m_des->UncheckedSetKey(dir, key+8);
432
 
        memcpy(m_x3, key+(dir==DECRYPTION?0:2*8), BLOCKSIZE);
 
437
        memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE);
 
438
        m_des->RawSetKey(GetCipherDirection(), key + 8);
 
439
        memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE);
433
440
}
434
441
 
435
442
void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const