Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib More Flexelint fixes...
details: https://anonhg.NetBSD.org/src/rev/670eace1386d
branches: trunk
changeset: 747933:670eace1386d
user: agc <agc%NetBSD.org@localhost>
date: Tue Oct 06 02:26:05 2009 +0000
description:
More Flexelint fixes from phk - just low-hanging fruit for just now -
many thanks!
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/create.c | 103 ++++++++++++---------
crypto/external/bsd/netpgp/dist/src/lib/crypto.c | 34 +++---
crypto/external/bsd/netpgp/dist/src/lib/keyring.c | 36 +++---
3 files changed, 94 insertions(+), 79 deletions(-)
diffs (truncated from 591 to 300 lines):
diff -r 854abac05be3 -r 670eace1386d crypto/external/bsd/netpgp/dist/src/lib/create.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/create.c Tue Oct 06 00:17:24 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/create.c Tue Oct 06 02:26:05 2009 +0000
@@ -57,13 +57,12 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: create.c,v 1.19 2009/06/13 05:25:08 agc Exp $");
+__RCSID("$NetBSD: create.c,v 1.20 2009/10/06 02:26:05 agc Exp $");
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
-#include <sys/mman.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
@@ -104,7 +103,7 @@
{
return __ops_write_length(output, length) &&
__ops_write_scalar(output, (unsigned)(type -
- OPS_PTAG_SIG_SUBPKT_BASE), 1);
+ (unsigned)OPS_PTAG_SIG_SUBPKT_BASE), 1);
}
/*
@@ -166,7 +165,7 @@
static unsigned
mpi_length(const BIGNUM *bn)
{
- return 2 + (BN_num_bits(bn) + 7) / 8;
+ return (unsigned)(2 + (BN_num_bits(bn) + 7) / 8);
}
static unsigned
@@ -194,7 +193,7 @@
len = mpi_length(key->key.rsa.d) + mpi_length(key->key.rsa.p) +
mpi_length(key->key.rsa.q) + mpi_length(key->key.rsa.u);
- return len + pubkey_length(&key->pubkey);
+ return (unsigned)(len + pubkey_length(&key->pubkey));
default:
(void) fprintf(stderr,
"seckey_length: unknown key algorithm\n");
@@ -213,7 +212,7 @@
__ops_fast_create_rsa_pubkey(__ops_pubkey_t *key, time_t t,
BIGNUM *n, BIGNUM *e)
{
- key->version = 4;
+ key->version = OPS_V4;
key->birthtime = t;
key->alg = OPS_PKA_RSA;
key->key.rsa.n = n;
@@ -362,10 +361,9 @@
case OPS_S2KS_SALTED:
/* RFC4880: section 3.7.1.1 and 3.7.1.2 */
- done = 0;
- for (i = 0; done < CAST_KEY_LENGTH; i++) {
- unsigned int j = 0;
+ for (done = 0, i = 0; done < CAST_KEY_LENGTH; i++) {
unsigned char zero = 0;
+ unsigned j;
int needed;
int size;
@@ -397,9 +395,9 @@
* if more in hash than is needed by session key, use
* the leftmost octets
*/
- (void) memcpy(sesskey + (i * OPS_SHA1_HASH_SIZE),
+ (void) memcpy(&sesskey[i * OPS_SHA1_HASH_SIZE],
hashed, (unsigned)size);
- done += size;
+ done += (unsigned)size;
if (done > CAST_KEY_LENGTH) {
(void) fprintf(stderr,
"write_seckey_body: short add\n");
@@ -429,7 +427,7 @@
__ops_encrypt_init(&crypted);
if (__ops_get_debug_level(__FILE__)) {
- unsigned int i2 = 0;
+ unsigned i2;
(void) fprintf(stderr, "\nWRITING:\niv=");
for (i2 = 0; i2 < __ops_block_size(key->alg); i2++) {
@@ -520,7 +518,7 @@
const __ops_key_t *keydata,
const unsigned armoured)
{
- unsigned int i = 0, j = 0;
+ unsigned int i, j;
if (armoured) {
__ops_writer_push_armoured(output, OPS_PGP_PUBLIC_KEY_BLOCK);
@@ -588,7 +586,7 @@
const size_t pplen,
unsigned armoured)
{
- unsigned i = 0, j = 0;
+ unsigned i, j;
if (armoured) {
__ops_writer_push_armoured(output, OPS_PGP_PRIVATE_KEY_BLOCK);
@@ -794,12 +792,12 @@
}
/* checksum or hash */
switch (key->s2k_usage) {
- case 0:
- case 255:
+ case OPS_S2KU_NONE:
+ case OPS_S2KU_ENCRYPTED:
length += 2;
break;
- case 254:
+ case OPS_S2KU_ENCRYPTED_AND_HASHED:
length += OPS_CHECKHASH_SIZE;
break;
@@ -810,7 +808,7 @@
}
/* secret key and public key MPIs */
- length += seckey_length(key);
+ length += (unsigned)seckey_length(key);
return __ops_write_ptag(output, OPS_PTAG_CT_SECRET_KEY) &&
/* __ops_write_length(output,1+4+1+1+seckey_length(key)+2) && */
@@ -846,7 +844,7 @@
__ops_output_delete(__ops_output_t *output)
{
writer_info_delete(&output->writer);
- (void) free(output);
+ free(output);
}
/**
@@ -859,8 +857,8 @@
unsigned
__ops_calc_sesskey_checksum(__ops_pk_sesskey_t *sesskey, unsigned char cs[2])
{
- unsigned int i = 0;
unsigned long checksum = 0;
+ unsigned int i;
if (!__ops_is_sa_supported(sesskey->symm_alg)) {
return 0;
@@ -885,7 +883,7 @@
static unsigned
create_unencoded_m_buf(__ops_pk_sesskey_t *sesskey, unsigned char *m_buf)
{
- int i = 0;
+ int i;
/* m_buf is the buffer which will be encoded in PKCS#1 block */
/* encoding to form the "m" value used in the */
@@ -902,6 +900,7 @@
return 0;
}
for (i = 0; i < CAST_KEY_LENGTH; i++) {
+ /* XXX - Flexelint - Warning 679: Suspicious Truncation in arithmetic expression combining with pointer */
m_buf[1 + i] = sesskey->key[i];
}
@@ -933,7 +932,7 @@
return 0;
}
- k = BN_num_bytes(pubkey->key.rsa.n);
+ k = (unsigned)BN_num_bytes(pubkey->key.rsa.n);
if (mLen > k - 11) {
(void) fprintf(stderr, "encode_m_buf: message too long\n");
return 0;
@@ -943,7 +942,7 @@
EM[1] = 0x02;
/* add non-zero random bytes of length k - mLen -3 */
- for (i = 2; i < k - mLen - 1; ++i) {
+ for (i = 2; i < (k - mLen) - 1; ++i) {
do {
__ops_random(EM + i, 1);
} while (EM[i] == 0);
@@ -959,7 +958,7 @@
(void) memcpy(EM + i, M, mLen);
if (__ops_get_debug_level(__FILE__)) {
- unsigned int i2 = 0;
+ unsigned int i2;
(void) fprintf(stderr, "Encoded Message: \n");
for (i2 = 0; i2 < mLen; i2++) {
@@ -992,13 +991,26 @@
* can be any, we're hardcoding RSA for now
*/
- const __ops_pubkey_t *pubkey = __ops_get_pubkey(key);
-#define SZ_UNENCODED_M_BUF CAST_KEY_LENGTH+1+2
- unsigned char unencoded_m_buf[SZ_UNENCODED_M_BUF];
- const size_t sz_encoded_m_buf = BN_num_bytes(pubkey->key.rsa.n);
- unsigned char *encoded_m_buf = calloc(1, sz_encoded_m_buf);
+#define SZ_UNENCODED_M_BUF (CAST_KEY_LENGTH + 1 + 2)
+
+ const __ops_pubkey_t *pubkey;
+ __ops_pk_sesskey_t *sesskey;
+ unsigned char unencoded_m_buf[SZ_UNENCODED_M_BUF];
+ unsigned char *encoded_m_buf;
+ size_t sz_encoded_m_buf;
- __ops_pk_sesskey_t *sesskey = calloc(1, sizeof(*sesskey));
+ pubkey = __ops_get_pubkey(key);
+ sz_encoded_m_buf = BN_num_bytes(pubkey->key.rsa.n);
+ if ((encoded_m_buf = calloc(1, sz_encoded_m_buf)) == NULL) {
+ (void) fprintf(stderr,
+ "__ops_create_pk_sesskey: can't allocate\n");
+ return NULL;
+ }
+ if ((sesskey = calloc(1, sizeof(*sesskey))) == NULL) {
+ (void) fprintf(stderr,
+ "__ops_create_pk_sesskey: can't allocate\n");
+ return NULL;
+ }
if (key->type != OPS_PTAG_CT_PUBLIC_KEY) {
(void) fprintf(stderr,
"__ops_create_pk_sesskey: bad type\n");
@@ -1009,7 +1021,7 @@
sizeof(sesskey->key_id));
if (__ops_get_debug_level(__FILE__)) {
- unsigned int i = 0;
+ unsigned int i;
(void) fprintf(stderr, "Encrypting for RSA key id : ");
for (i = 0; i < sizeof(sesskey->key_id); i++) {
@@ -1029,7 +1041,7 @@
__ops_random(sesskey->key, CAST_KEY_LENGTH);
if (__ops_get_debug_level(__FILE__)) {
- unsigned int i = 0;
+ unsigned int i;
(void) fprintf(stderr,
"CAST5 session key created (len=%d):\n ",
@@ -1040,11 +1052,11 @@
(void) fprintf(stderr, "\n");
}
if (create_unencoded_m_buf(sesskey, &unencoded_m_buf[0]) == 0) {
- (void) free(encoded_m_buf);
+ free(encoded_m_buf);
return NULL;
}
if (__ops_get_debug_level(__FILE__)) {
- unsigned int i = 0;
+ unsigned int i;
printf("unencoded m buf:\n");
for (i = 0; i < SZ_UNENCODED_M_BUF; i++) {
@@ -1058,10 +1070,10 @@
/* and encrypt it */
if (!__ops_rsa_encrypt_mpi(encoded_m_buf, sz_encoded_m_buf, pubkey,
&sesskey->params)) {
- (void) free(encoded_m_buf);
+ free(encoded_m_buf);
return NULL;
}
- (void) free(encoded_m_buf);
+ free(encoded_m_buf);
return sesskey;
}
@@ -1075,6 +1087,7 @@
unsigned
__ops_write_pk_sesskey(__ops_output_t *output, __ops_pk_sesskey_t *pksk)
{
+ /* XXX - Flexelint - Pointer parameter 'pksk' (line 1076) could be declared as pointing to const */
if (pksk == NULL) {
(void) fprintf(stderr,
"__ops_write_pk_sesskey: NULL pksk\n");
@@ -1157,7 +1170,7 @@
const __ops_litdata_type_t type,
__ops_output_t *output)
{
- __ops_memory_t *mem = NULL;
+ __ops_memory_t *mem;
unsigned ret;
size_t len;
@@ -1192,8 +1205,8 @@
__ops_filewrite(const char *filename, const char *buf,
const size_t len, const unsigned overwrite)
{
- int flags = 0;
- int fd = 0;
+ int flags;
+ int fd;
flags = O_WRONLY | O_CREAT;
if (overwrite) {
Home |
Main Index |
Thread Index |
Old Index