aboutsummaryrefslogtreecommitdiff
path: root/src/lib/crypto/crypto_tests/t_cksum.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/crypto/crypto_tests/t_cksum.c')
-rw-r--r--src/lib/crypto/crypto_tests/t_cksum.c215
1 files changed, 108 insertions, 107 deletions
diff --git a/src/lib/crypto/crypto_tests/t_cksum.c b/src/lib/crypto/crypto_tests/t_cksum.c
index 5fab869..5aca50f 100644
--- a/src/lib/crypto/crypto_tests/t_cksum.c
+++ b/src/lib/crypto/crypto_tests/t_cksum.c
@@ -1,3 +1,4 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* lib/crypto/md5/t_cksum.c
*
@@ -34,50 +35,50 @@
#define MD5_K5BETA_COMPAT
#define MD4_K5BETA_COMPAT
-#if MD == 4
+#if MD == 4
extern struct krb5_keyhash_provider krb5int_keyhash_md4des;
#define khp krb5int_keyhash_md4des
#endif
-#if MD == 5
+#if MD == 5
extern struct krb5_keyhash_provider krb5int_keyhash_md5des;
#define khp krb5int_keyhash_md5des
#endif
static void
print_checksum(text, number, message, checksum)
- char *text;
- int number;
- char *message;
- krb5_data *checksum;
+ char *text;
+ int number;
+ char *message;
+ krb5_data *checksum;
{
- int i;
+ int i;
- printf("%s MD%d checksum(\"%s\") = ", text, number, message);
- for (i=0; i<checksum->length; i++)
- printf("%02x", (unsigned char) checksum->data[i]);
- printf("\n");
+ printf("%s MD%d checksum(\"%s\") = ", text, number, message);
+ for (i=0; i<checksum->length; i++)
+ printf("%02x", (unsigned char) checksum->data[i]);
+ printf("\n");
}
static void
parse_hexstring(const char *s, krb5_data *dat)
{
- size_t i, len;
- unsigned int byte;
- unsigned char *cp;
-
- len = strlen(s);
- cp = malloc(len / 2);
- dat->data = (char *)cp;
- if (cp == NULL) {
- dat->length = 0;
- return;
- }
- dat->length = len / 2;
- for (i = 0; i + 1 < len; i += 2) {
- sscanf(&s[i], "%2x", &byte);
- *cp++ = byte;
- }
+ size_t i, len;
+ unsigned int byte;
+ unsigned char *cp;
+
+ len = strlen(s);
+ cp = malloc(len / 2);
+ dat->data = (char *)cp;
+ if (cp == NULL) {
+ dat->length = 0;
+ return;
+ }
+ dat->length = len / 2;
+ for (i = 0; i + 1 < len; i += 2) {
+ sscanf(&s[i], "%2x", &byte);
+ *cp++ = byte;
+ }
}
/*
@@ -89,97 +90,97 @@ krb5_octet testkey[8] = { 0x45, 0x01, 0x49, 0x61, 0x58, 0x19, 0x1a, 0x3d };
int
main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
- int msgindex;
- krb5_boolean valid;
- size_t length;
- krb5_keyblock keyblock;
- krb5_key key;
- krb5_error_code kret=0;
- krb5_data plaintext, newstyle_checksum, knowncksum_dat;
-
- /* this is a terrible seed, but that's ok for the test. */
+ int msgindex;
+ krb5_boolean valid;
+ size_t length;
+ krb5_keyblock keyblock;
+ krb5_key key;
+ krb5_error_code kret=0;
+ krb5_data plaintext, newstyle_checksum, knowncksum_dat;
- plaintext.length = 8;
- plaintext.data = (char *) testkey;
+ /* this is a terrible seed, but that's ok for the test. */
- krb5_c_random_seed(/* XXX */ 0, &plaintext);
+ plaintext.length = 8;
+ plaintext.data = (char *) testkey;
- keyblock.enctype = ENCTYPE_DES_CBC_CRC;
- keyblock.length = sizeof(testkey);
- keyblock.contents = testkey;
+ krb5_c_random_seed(/* XXX */ 0, &plaintext);
- krb5_k_create_key(NULL, &keyblock, &key);
+ keyblock.enctype = ENCTYPE_DES_CBC_CRC;
+ keyblock.length = sizeof(testkey);
+ keyblock.contents = testkey;
- length = khp.hashsize;
+ krb5_k_create_key(NULL, &keyblock, &key);
- newstyle_checksum.length = length;
+ length = khp.hashsize;
- if (!(newstyle_checksum.data = (char *)
- malloc((unsigned) newstyle_checksum.length))) {
- printf("cannot get memory for new style checksum\n");
- return(ENOMEM);
- }
- for (msgindex = 1; msgindex + 1 < argc; msgindex += 2) {
- plaintext.length = strlen(argv[msgindex]);
- plaintext.data = argv[msgindex];
+ newstyle_checksum.length = length;
- if ((kret = (*(khp.hash))(key, 0, 0, &plaintext, &newstyle_checksum))) {
- printf("krb5_calculate_checksum choked with %d\n", kret);
- break;
- }
- print_checksum("correct", MD, argv[msgindex], &newstyle_checksum);
-
- if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &newstyle_checksum,
- &valid))) {
- printf("verify on new checksum choked with %d\n", kret);
- break;
- }
- if (!valid) {
- printf("verify on new checksum failed\n");
- kret = 1;
- break;
- }
- printf("Verify succeeded for \"%s\"\n", argv[msgindex]);
-
- newstyle_checksum.data[0]++;
- if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &newstyle_checksum,
- &valid))) {
- printf("verify on new checksum choked with %d\n", kret);
- break;
- }
- if (valid) {
- printf("verify on new checksum succeeded, but shouldn't have\n");
- kret = 1;
- break;
- }
- printf("Verify of bad checksum OK for \"%s\"\n", argv[msgindex]);
- parse_hexstring(argv[msgindex+1], &knowncksum_dat);
- if (knowncksum_dat.data == NULL) {
- printf("parse_hexstring failed\n");
- kret = 1;
- break;
- }
- if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &knowncksum_dat,
- &valid))) {
- printf("verify on known checksum choked with %d\n", kret);
- break;
+ if (!(newstyle_checksum.data = (char *)
+ malloc((unsigned) newstyle_checksum.length))) {
+ printf("cannot get memory for new style checksum\n");
+ return(ENOMEM);
}
- if (!valid) {
- printf("verify on known checksum failed\n");
- kret = 1;
- break;
+ for (msgindex = 1; msgindex + 1 < argc; msgindex += 2) {
+ plaintext.length = strlen(argv[msgindex]);
+ plaintext.data = argv[msgindex];
+
+ if ((kret = (*(khp.hash))(key, 0, 0, &plaintext, &newstyle_checksum))) {
+ printf("krb5_calculate_checksum choked with %d\n", kret);
+ break;
+ }
+ print_checksum("correct", MD, argv[msgindex], &newstyle_checksum);
+
+ if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &newstyle_checksum,
+ &valid))) {
+ printf("verify on new checksum choked with %d\n", kret);
+ break;
+ }
+ if (!valid) {
+ printf("verify on new checksum failed\n");
+ kret = 1;
+ break;
+ }
+ printf("Verify succeeded for \"%s\"\n", argv[msgindex]);
+
+ newstyle_checksum.data[0]++;
+ if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &newstyle_checksum,
+ &valid))) {
+ printf("verify on new checksum choked with %d\n", kret);
+ break;
+ }
+ if (valid) {
+ printf("verify on new checksum succeeded, but shouldn't have\n");
+ kret = 1;
+ break;
+ }
+ printf("Verify of bad checksum OK for \"%s\"\n", argv[msgindex]);
+ parse_hexstring(argv[msgindex+1], &knowncksum_dat);
+ if (knowncksum_dat.data == NULL) {
+ printf("parse_hexstring failed\n");
+ kret = 1;
+ break;
+ }
+ if ((kret = (*(khp.verify))(key, 0, 0, &plaintext, &knowncksum_dat,
+ &valid))) {
+ printf("verify on known checksum choked with %d\n", kret);
+ break;
+ }
+ if (!valid) {
+ printf("verify on known checksum failed\n");
+ kret = 1;
+ break;
+ }
+ printf("Verify on known checksum succeeded\n");
+ kret = 0;
}
- printf("Verify on known checksum succeeded\n");
- kret = 0;
- }
- free(newstyle_checksum.data);
- if (!kret)
- printf("%d tests passed successfully for MD%d checksum\n", (argc-1)/2, MD);
+ free(newstyle_checksum.data);
+ if (!kret)
+ printf("%d tests passed successfully for MD%d checksum\n", (argc-1)/2, MD);
- krb5_k_free_key(NULL, key);
+ krb5_k_free_key(NULL, key);
- return(kret);
+ return(kret);
}