cbc_crypt, des_setparity, or ecb_crypt Subroutine

转自:http://www.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/libs/commtrf1/cbc_crypt.htm

Purpose

Implements Data Encryption Standard (DES) encryption routines.

Library

DES library (libdes.a)

Syntax

# include <des_crypt.h>
int ecb_crypt (key, data, datalen, mode)
char *key;
char *data;
unsigned datalen;
unsigned mode;
int cbc_crypt(key, data, datalen, mode, ivec)
char *key;
char *data;
unsigned datalen;
unsigned mode;
char ivec;
void des_setparity(key)
char *key;

Description

The ecb_crypt and cbc_crypt subroutines implement DES encryption routines, set by the National Bureau of Standards.

  • The ecb_crypt subroutine encrypts in ECB (Electronic Code Book) mode, which encrypts blocks of data independently.
  • The cbc_crypt subroutine encrypts in CBC (Cipher Block Chaining) mode, which chains together successive blocks. CBC mode protects against insertions, deletions, and substitutions of blocks. Also, regularities in the clear text will not appear in the cipher text.
    Note: The DES library must be installed to use these subroutines.

Parameters

dataSpecifies that the data is to be either encrypted or decrypted.
datalenSpecifies the length in bytes of data. The length must be a multiple of 8.
keySpecifies the 8-byte encryption key with parity. To set the parity for the key, which for DES is in the low bit of each byte, use the des_setparity subroutine.
ivecInitializes the vector for the chaining in 8-byte. This is updated to the next initialization vector upon return.
modeSpecifies whether data is to be encrypted or decrypted. This parameter is formed by logically ORing theDES_ENCRYPT or DES_DECRYPT symbols. For software versus hardware encryption, logically OR the DES_HW or DES_SWsymbols. These four symbols are defined in the /usr/include/des_crypt.h file.

Return Values

DESERR_BADPARAMSpecifies that a bad parameter was passed to routine.
DESERR_HWERRSpecifies that an error occurred in the hardware or driver.
DESERR_NOHWDEVICESpecifies that encryption succeeded, but was done in software instead of the requested hardware.
DESERR_NONESpecifies no error.
Note: Given the  stat variable, for example, which contains the return value for either the  ecb_crypt or cbc_crypt subroutine, the  DES_FAILED(stat) macro is false only for the  DESERR_NONE and  DESERR_NOHWDEVICEreturn values.

Implementation Specifics

These subroutines are not available for export outside the United States.

Files

/usr/include/des_crypt.hDefines macros and needed symbols for the mode parameter.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值