本文整理汇总了C++中des_ecb_encrypt函数的典型用法代码示例。如果您正苦于以下问题:C++ des_ecb_encrypt函数的具体用法?C++ des_ecb_encrypt怎么用?C++ des_ecb_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了des_ecb_encrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ATF_TC_BODY
ATF_TC_BODY(ecb, tc)
{
int i;
des_cblock in, out, outin;
des_key_schedule ks;
for (i = 0; i < NUM_TESTS; i++) {
des_set_key_unchecked(&key_data[i], ks);
memcpy(in, plain_data[i], 8);
memset(out, 0, 8);
memset(outin, 0, 8);
des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);
if (memcmp(out, cipher_data[i], 8) != 0) {
atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s "
"o=%s act=%s\n", i + 1,
pt(key_data[i]), pt(in),
pt(cipher_data[i]), pt(out));
}
if (memcmp(in, outin, 8) != 0) {
atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s "
"o=%s act=%s\n", i + 1,
pt(key_data[i]), pt(out), pt(in),
pt(outin));
}
}
}
示例2: desDecryptCBC
int desDecryptCBC( CRYPT_INFO *cryptInfo, BYTE *buffer, int noBytes )
{
BYTE temp[ DES_BLOCKSIZE ];
int blockCount = noBytes / DES_BLOCKSIZE;
/* Make sure the data length is a multiple of the block size */
if( noBytes % DES_BLOCKSIZE )
return( CRYPT_BADPARM3 );
while( blockCount-- )
{
int i;
/* Save the ciphertext */
memcpy( temp, buffer, DES_BLOCKSIZE );
/* Decrypt a block of data */
des_ecb_encrypt( ( C_Block * ) buffer, ( C_Block * ) buffer,
cryptInfo->key, DES_DECRYPT );
/* XOR the buffer contents with the encrypted IV */
for( i = 0; i < DES_BLOCKSIZE; i++ )
buffer[ i ] ^= cryptInfo->currentIV[ i ];
/* Shift the ciphertext into the IV */
memcpy( cryptInfo->currentIV, temp, DES_BLOCKSIZE );
/* Move on to next block of data */
buffer += DES_BLOCKSIZE;
}
return( CRYPT_OK );
}
示例3: ofb64_decrypt
int
ofb64_decrypt(int data)
{
struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1];
int idx;
if (data == -1) {
/*
* Back up one byte. It is assumed that we will
* never back up more than one byte. If we do, this
* may or may not work.
*/
if (stp->str_index)
--stp->str_index;
return(0);
}
idx = stp->str_index++;
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
stp->str_index = 1; /* Next time will be 1 */
idx = 0; /* But now use 0 */
}
return(data ^ stp->str_feed[idx]);
}
示例4: DesEncrypt
static void DesEncrypt(
u_char *clear, /* IN 8 octets */
u_char *key, /* IN 7 octets */
u_char *cipher /* OUT 8 octets */
)
{
des_cblock des_key;
des_key_schedule key_schedule;
MakeKey(key, des_key);
des_set_key(&des_key, key_schedule);
#if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif
des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
#if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif
}
示例5: block_encrypt
static void block_encrypt(struct block_state *self, const uint8_t *in, uint8_t *out)
{
#ifdef PCT_DES3_MODULE
des3_ecb_encrypt(in, out, &self->sk);
#else
des_ecb_encrypt(in, out, &self->sk);
#endif
}
示例6: des1_decrypt
static void
des1_decrypt(caddr_t key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb_encrypt(cb, cb, p[0], DES_DECRYPT);
}
示例7: des1_encrypt
static void
des1_encrypt(void *key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb_encrypt(cb, cb, p[0], DES_ENCRYPT);
}
示例8: fb64_start
static int
fb64_start(struct fb *fbp, int dir, int server __unused)
{
size_t x;
unsigned char *p;
int state;
switch (dir) {
case DIR_DECRYPT:
/*
* This is simply a request to have the other side
* start output (our input). He will negotiate an
* IV so we need not look for it.
*/
state = fbp->state[dir-1];
if (state == FAILED)
state = IN_PROGRESS;
break;
case DIR_ENCRYPT:
state = fbp->state[dir-1];
if (state == FAILED)
state = IN_PROGRESS;
else if ((state & NO_SEND_IV) == 0)
break;
if (!VALIDKEY(fbp->krbdes_key)) {
fbp->need_start = 1;
break;
}
state &= ~NO_SEND_IV;
state |= NO_RECV_IV;
if (encrypt_debug_mode)
printf("Creating new feed\r\n");
/*
* Create a random feed and send it over.
*/
des_random_key((Block *)fbp->temp_feed);
des_ecb_encrypt((Block *)fbp->temp_feed, (Block *)fbp->temp_feed,
fbp->krbdes_sched, 1);
p = fbp->fb_feed + 3;
*p++ = ENCRYPT_IS;
p++;
*p++ = FB64_IV;
for (x = 0; x < sizeof(Block); ++x) {
if ((*p++ = fbp->temp_feed[x]) == IAC)
*p++ = IAC;
}
*p++ = IAC;
*p++ = SE;
printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
net_write(fbp->fb_feed, p - fbp->fb_feed);
break;
default:
return(FAILED);
}
return(fbp->state[dir-1] = state);
}
示例9: desDecryptCFB
int desDecryptCFB( CRYPT_INFO *cryptInfo, BYTE *buffer, int noBytes )
{
BYTE temp[ DES_BLOCKSIZE ];
int i, ivCount = cryptInfo->ivCount;
/* If there's any encrypted material left in the IV, use it now */
if( ivCount )
{
int bytesToUse;
/* Find out how much material left in the encrypted IV we can use */
bytesToUse = DES_BLOCKSIZE - ivCount;
if( noBytes < bytesToUse )
bytesToUse = noBytes;
/* Decrypt the data */
memcpy( temp, buffer, bytesToUse );
for( i = 0; i < bytesToUse; i++ )
buffer[ i ] ^= cryptInfo->currentIV[ i + ivCount ];
memcpy( cryptInfo->currentIV + ivCount, temp, bytesToUse );
/* Adjust the byte count and buffer position */
noBytes -= bytesToUse;
buffer += bytesToUse;
ivCount += bytesToUse;
}
while( noBytes )
{
ivCount = ( noBytes > DES_BLOCKSIZE ) ? DES_BLOCKSIZE : noBytes;
/* Encrypt the IV */
des_ecb_encrypt( ( C_Block * ) cryptInfo->currentIV,
( C_Block * ) cryptInfo->currentIV,
cryptInfo->key, DES_ENCRYPT );
/* Save the ciphertext */
memcpy( temp, buffer, ivCount );
/* XOR the buffer contents with the encrypted IV */
for( i = 0; i < ivCount; i++ )
buffer[ i ] ^= cryptInfo->currentIV[ i ];
/* Shift the ciphertext into the IV */
memcpy( cryptInfo->currentIV, temp, ivCount );
/* Move on to next block of data */
noBytes -= ivCount;
buffer += ivCount;
}
/* Remember how much of the IV is still available for use */
cryptInfo->ivCount = ( ivCount % DES_BLOCKSIZE );
return( CRYPT_OK );
}
示例10: DesEncrypt
/* Do the DesEncryption */
void
DesEncrypt(unsigned char *clear, unsigned char *key, unsigned char *cipher)
{
des_cblock des_key;
des_key_schedule key_schedule;
MakeKey(key, des_key);
des_set_key(&des_key, key_schedule);
des_ecb_encrypt((des_cblock *) clear, (des_cblock *) cipher, key_schedule, 1);
}
示例11: block_encrypt
static void block_encrypt(block_state *self, unsigned char *in, unsigned char *out)
{
int rc;
#ifdef PCT_DES3_MODULE
rc = des3_ecb_encrypt(in, out, &self->sk);
#else
rc = des_ecb_encrypt(in, out, &self->sk);
#endif
assert(rc == CRYPT_OK);
}
示例12: ofb64_encrypt
/*
* DES 64 bit Output Feedback
*
* key --->+-----+
* +->| DES |--+
* | +-----+ |
* +-----------+
* v
* INPUT -------->(+) ----> DATA
*
* Given:
* iV: Initial vector, 64 bits (8 bytes) long.
* Dn: the nth chunk of 64 bits (8 bytes) of data to encrypt (decrypt).
* On: the nth chunk of 64 bits (8 bytes) of encrypted (decrypted) output.
*
* V0 = DES(iV, key)
* V(n+1) = DES(Vn, key)
* On = Dn ^ Vn
*/
void
ofb64_encrypt(unsigned char *s, int c)
{
struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1];
int idx;
idx = stp->str_index;
while (c-- > 0) {
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
idx = 0;
}
*s++ ^= stp->str_feed[idx];
idx++;
}
stp->str_index = idx;
}
示例13: desTestLoop
static int desTestLoop( DES_TEST *testData, int iterations, int operation )
{
BYTE temp[ DES_BLOCKSIZE ];
BYTE key[ DES_EXPANDED_KEYSIZE ];
int i;
for( i = 0; i < iterations; i++ )
{
memcpy( temp, testData[ i ].plaintext, DES_BLOCKSIZE );
key_sched( ( C_Block * ) testData[ i ].key,
*( ( Key_schedule * ) key ) );
des_ecb_encrypt( ( C_Block * ) temp, ( C_Block * ) temp,
*( ( Key_schedule * ) key ), operation );
if( memcmp( testData[ i ].ciphertext, temp, DES_BLOCKSIZE ) )
return( CRYPT_ERROR );
}
return( CRYPT_OK );
}
示例14: des_string_to_key
char *XTRAMangle(char *xtrace, char *cryptpw)
{
static char res[256];
char *rptr, *xptr;
int count;
unsigned char plain[8], enc[8];
des_cblock key;
des_key_schedule sched;
des_string_to_key(cryptpw, &key);
des_set_key(&key, sched);
rptr = res;
/* Overflow protect; 192 chars expands to 256, overflowing res */
if (strlen(xtrace) > 191) {
xtrace[191] = '\0';
}
/* Step thru 'xtrace' 8 chars at a time, encrypt as we go */
xptr = xtrace;
count = 0;
bzero(plain, sizeof(plain));
while (*xptr) {
plain[count++ % 8] = *xptr++;
if (! *xptr || (count % 8) == 0) {
/* Encrypt block of (up to) 8 and pump out coded ASCII */
des_ecb_encrypt((des_cblock *)plain,(des_cblock *)enc, sched, 1);
bzero(plain, sizeof(plain));
*rptr++ = '0' + (enc[0] & 0x3f);
*rptr++ = '0' + (enc[0] >> 6) + ((enc[1] & 0x0f) << 2);
*rptr++ = '0' + (enc[1] >> 4) + ((enc[2] & 0x03) << 4);
*rptr++ = '0' + (enc[2] >> 2);
*rptr++ = '0' + (enc[3] & 0x3f);
*rptr++ = '0' + (enc[3] >> 6) + ((enc[4] & 0x0f) << 2);
*rptr++ = '0' + (enc[4] >> 4) + ((enc[5] & 0x03) << 4);
*rptr++ = '0' + (enc[5] >> 2);
*rptr++ = '0' + (enc[6] & 0x3f);
*rptr++ = '0' + (enc[6] >> 6) + ((enc[7] & 0x0f) << 2);
*rptr++ = '0' + (enc[7] >> 4) + ((time(NULL) & 0x03) << 4);
}
}
示例15: desDecryptECB
int desDecryptECB( CRYPT_INFO *cryptInfo, BYTE *buffer, int noBytes )
{
int blockCount = noBytes / DES_BLOCKSIZE;
/* Make sure the data length is a multiple of the block size */
if( noBytes % DES_BLOCKSIZE )
return( CRYPT_BADPARM3 );
while( blockCount-- )
{
/* Decrypt a block of data */
des_ecb_encrypt( ( C_Block * ) buffer, ( C_Block * ) buffer,
cryptInfo->key, DES_DECRYPT );
/* Move on to next block of data */
buffer += DES_BLOCKSIZE;
}
return( CRYPT_OK );
}