#include <blowfish.hpp>
|
| blowfish () |
|
void | start (unsigned char *ucKey, uint64_t n, const sblock &roChain=sblock(0UL, 0UL)) |
|
void | reset_chain () |
|
void | encrypt (unsigned char *buf, uint64_t n, int iMode=CFB) |
|
void | decrypt (unsigned char *buf, uint64_t n, int iMode=CFB) |
|
void | encrypt (const unsigned char *in, unsigned char *out, uint64_t n, int iMode=CFB) |
|
void | decrypt (const unsigned char *in, unsigned char *out, uint64_t n, int iMode=CFB) |
|
Definition at line 139 of file blowfish.hpp.
◆ anonymous enum
◆ blowfish()
fc::blowfish::blowfish |
( |
| ) |
|
◆ decrypt() [1/2]
void fc::blowfish::decrypt |
( |
const unsigned char * | in, |
|
|
unsigned char * | out, |
|
|
uint64_t | n, |
|
|
int | iMode = CFB ) |
Definition at line 581 of file blowfish.cpp.
582{
583
584 if((n==0)||(n%8!=0))
585 FC_THROW_EXCEPTION( exception,
"invalid buffer length ${n}, not multiple of 8", (
"n", n) );
586 sblock work;
588 {
589 sblock crypt, chain(m_oChain);
590 for(; n >= 8; n -= 8, in += 8)
591 {
593 crypt = work;
595 work ^= chain;
596 chain = crypt;
598 }
599 }
600 else if(iMode ==
CFB)
601 {
602 sblock crypt, chain(m_oChain);
603 for(; n >= 8; n -= 8, in += 8)
604 {
607 crypt = work;
608 work ^= chain;
609 chain = crypt;
611 }
612 }
613 else
614 {
615 for(; n >= 8; n -= 8, in += 8)
616 {
620 }
621 }
622}
void decrypt(unsigned char *buf, uint64_t n, int iMode=CFB)
void encrypt(unsigned char *buf, uint64_t n, int iMode=CFB)
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
void BlockToBytes(sblock const &b, unsigned char *p)
void BytesToBlock(unsigned char const *p, sblock &b)
◆ decrypt() [2/2]
void fc::blowfish::decrypt |
( |
unsigned char * | buf, |
|
|
uint64_t | n, |
|
|
int | iMode = CFB ) |
Definition at line 493 of file blowfish.cpp.
494{
495
496 if((n==0)||(n%8!=0))
497 FC_THROW_EXCEPTION( exception,
"invalid buffer length ${n}, not multiple of 8", (
"n", n) );
498 sblock work;
500 {
501 sblock crypt, chain(m_oChain);
502 for(; n >= 8; n -= 8)
503 {
505 crypt = work;
507 work ^= chain;
508 chain = crypt;
510 }
511 }
512 else if(iMode ==
CFB)
513 {
514 sblock crypt, chain(m_oChain);
515 for(; n >= 8; n -= 8)
516 {
519 crypt = work;
520 work ^= chain;
521 chain = crypt;
523 }
524 }
525 else
526 {
527 for(; n >= 8; n -= 8)
528 {
532 }
533 }
534}
◆ encrypt() [1/2]
void fc::blowfish::encrypt |
( |
const unsigned char * | in, |
|
|
unsigned char * | out, |
|
|
uint64_t | n, |
|
|
int | iMode = CFB ) |
Definition at line 538 of file blowfish.cpp.
539{
540
541 if((n==0)||(n%8!=0))
542 FC_THROW_EXCEPTION( exception,
"invalid buffer length ${n}, not multiple of 8", (
"n", n) );
543 sblock work;
545 {
546 sblock chain(m_oChain);
547 for(; n >= 8; n -= 8, in += 8)
548 {
550 work ^= chain;
552 chain = work;
554 }
555 }
556 else if(iMode ==
CFB)
557 {
558 sblock chain(m_oChain);
559 for(; n >= 8; n -= 8, in += 8)
560 {
563 work ^= chain;
564 chain = work;
566 }
567 }
568 else
569 {
570 for(; n >= 8; n -= 8, in += 8)
571 {
575 }
576 }
577}
◆ encrypt() [2/2]
void fc::blowfish::encrypt |
( |
unsigned char * | buf, |
|
|
uint64_t | n, |
|
|
int | iMode = CFB ) |
Definition at line 450 of file blowfish.cpp.
451{
452
453 if((n==0)||(n%8!=0))
454 FC_THROW_EXCEPTION( exception,
"invalid buffer length ${n}, not multiple of 8", (
"n", n) );
455 sblock work;
457 {
458 sblock chain(m_oChain);
459 for(; n >= 8; n -= 8)
460 {
462 work ^= chain;
464 chain = work;
466 }
467 }
468 else if(iMode ==
CFB)
469 {
470 sblock chain(m_oChain);
471 for(; n >= 8; n -= 8)
472 {
475 work ^= chain;
476 chain = work;
478 }
479 }
480 else
481 {
482 for(; n >= 8; n -= 8)
483 {
487 }
488 }
489}
◆ reset_chain()
void fc::blowfish::reset_chain |
( |
| ) |
|
|
inline |
◆ start()
void fc::blowfish::start |
( |
unsigned char * | ucKey, |
|
|
uint64_t | n, |
|
|
const sblock & | roChain = sblock(0UL,0UL) ) |
Definition at line 306 of file blowfish.cpp.
307{
308 m_oChain0 = roChain;
309 m_oChain = roChain;
310
311 if(keysize<1)
313
314 if(keysize>56)
315 keysize = 56;
316 unsigned char aucLocalKey[56];
318 memcpy(aucLocalKey, ucKey,
static_cast<size_t>(keysize));
319
320
321 memcpy(m_auiP, scm_auiInitP,
sizeof m_auiP);
322 memcpy(m_auiS, scm_auiInitS,
sizeof m_auiS);
323
324 const unsigned char*
p = aucLocalKey;
325 unsigned int x=0;
326
328 for(i=0; i<18; i++)
329 {
330 x=0;
331 for(int n=4; n--; )
332 {
333
334 x <<= 8;
336 iCount++;
337 if(iCount == keysize)
338 {
339
340 iCount = 0;
342 }
343 }
344 m_auiP[i] ^= x;
345 }
346
347 sblock block(0UL,0UL);
348 for(i=0; i<18; )
349 encrypt(block), m_auiP[i++] = block.m_uil, m_auiP[i++] = block.m_uir;
351 for(int k=0; k<256; )
352 encrypt(block), m_auiS[
j][k++] = block.m_uil, m_auiS[
j][k++] = block.m_uir;
353}
memcpy((char *) pInfo->slotDescription, s, l)
The documentation for this class was generated from the following files: