Use NSS instead of beecrypt for encryption (Tomas Mraz)

This commit is contained in:
Panu Matilainen 2007-11-02 10:02:40 +02:00
parent 4bd5cb406e
commit afb00f0db4

View File

@ -37,8 +37,8 @@
#include <gelf.h>
#include <dwarf.h>
#include <beecrypt/beecrypt.h>
#include <rpmio.h>
#include <rpmpgp.h>
#include "hashtab.h"
#define DW_TAG_partial_unit 0x3c
@ -1301,22 +1301,27 @@ error_out:
return NULL;
}
static const pgpHashAlgo algorithms[] = { PGPHASHALGO_MD5,
PGPHASHALGO_SHA1, PGPHASHALGO_SHA256, PGPHASHALGO_SHA384, PGPHASHALGO_SHA512 };
/* Compute a fresh build ID bit-string from the editted file contents. */
static void
handle_build_id (DSO *dso, Elf_Data *build_id,
size_t build_id_offset, size_t build_id_size)
{
hashFunctionContext ctx;
const hashFunction *hf = NULL;
int i = hashFunctionCount ();
DIGEST_CTX ctx;
pgpHashAlgo algorithm;
int i = sizeof(algorithms)/sizeof(algorithms[0]);
void *digest = NULL;
size_t len;
while (i-- > 0)
{
hf = hashFunctionGet (i);
if (hf != NULL && hf->digestsize == build_id_size)
algorithm = algorithms[i];
if (rpmDigestLength(algorithm) == build_id_size)
break;
}
if (hf == NULL)
if (i < 0)
{
fprintf (stderr, "Cannot handle %Zu-byte build ID\n", build_id_size);
exit (1);
@ -1332,7 +1337,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
/* Clear the old bits so they do not affect the new hash. */
memset ((char *) build_id->d_buf + build_id_offset, 0, build_id_size);
hashFunctionContextInit (&ctx, hf);
ctx = rpmDigestInit(algorithm, 0);
/* Slurp the relevant header bits and section contents and feed them
into the hash function. The only bits we ignore are the offset
@ -1346,8 +1351,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
inline void process (const void *data, size_t size);
inline void process (const void *data, size_t size)
{
memchunk chunk = { .data = (void *) data, .size = size };
hashFunctionContextUpdateMC (&ctx, &chunk);
rpmDigestUpdate(ctx, data, size);
}
union
@ -1402,22 +1406,17 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
}
}
hashFunctionContextDigest (&ctx, (byte *) build_id->d_buf + build_id_offset);
hashFunctionContextFree (&ctx);
rpmDigestFinal(ctx, &digest, &len, 0);
memcpy((unsigned char *)build_id->d_buf + build_id_offset, digest, build_id_size);
free(digest);
elf_flagdata (build_id, ELF_C_SET, ELF_F_DIRTY);
/* Now format the build ID bits in hex to print out. */
{
const unsigned char * id = (unsigned char *) build_id->d_buf + build_id_offset;
const byte * id = (byte *)build_id->d_buf + build_id_offset;
char hex[build_id_size * 2 + 1];
int n = snprintf (hex, 3, "%02" PRIx8, id[0]);
assert (n == 2);
for (i = 1; i < build_id_size; ++i)
{
n = snprintf (&hex[i * 2], 3, "%02" PRIx8, id[i]);
assert (n == 2);
}
pgpHexCvt(hex, id, build_id_size);
puts (hex);
}
}