*
* This function verifies that @a cksum is a valid checksum for @a data. If
* the checksum type of @a cksum is a keyed checksum, @a key is used to verify
- * the checksum. The actual checksum key will be derived from @a key and @a
- * usage if key derivation is specified for the checksum type.
+ * the checksum. If the checksum type in @a cksum is 0 and @a key is not NULL,
+ * the mandatory checksum type for @a key will be used. The actual checksum
+ * key will be derived from @a key and @a usage if key derivation is specified
+ * for the checksum type.
*
* @note This function is similar to krb5_k_verify_checksum(), but operates
* on keyblock @a key.
*
* This function verifies that @a cksum is a valid checksum for @a data. If
* the checksum type of @a cksum is a keyed checksum, @a key is used to verify
- * the checksum. The actual checksum key will be derived from @a key and @a
- * usage if key derivation is specified for the checksum type.
+ * the checksum. If the checksum type in @a cksum is 0 and @a key is not NULL,
+ * the mandatory checksum type for @a key will be used. The actual checksum
+ * key will be derived from @a key and @a usage if key derivation is specified
+ * for the checksum type.
*
* @note This function is similar to krb5_c_verify_checksum(), but operates
* on opaque @a key.
krb5_keyblock kb, *kbp;
krb5_data plain;
krb5_checksum cksum;
- krb5_boolean verbose = FALSE;
+ krb5_cksumtype mtype;
+ krb5_boolean valid, verbose = FALSE;
int status = 0;
if (argc >= 2 && strcmp(argv[1], "-v") == 0)
if (!verbose)
break;
}
+
+ /* Test that the checksum verifies successfully. */
+ ret = krb5_c_verify_checksum(context, kbp, test->usage, &plain, &cksum,
+ &valid);
+ assert(!ret);
+ if (!valid) {
+ printf("test %d verify failed\n", (int)i);
+ status = 1;
+ if (!verbose)
+ break;
+ }
+
+ if (kbp != NULL) {
+ ret = krb5int_c_mandatory_cksumtype(context, kbp->enctype, &mtype);
+ assert(!ret);
+ if (test->sumtype == mtype) {
+ /* Test that a checksum type of 0 uses the mandatory checksum
+ * type for the key. */
+ cksum.checksum_type = 0;
+ ret = krb5_c_verify_checksum(context, kbp, test->usage, &plain,
+ &cksum, &valid);
+ assert(!ret && valid);
+ }
+ }
+
krb5_free_checksum_contents(context, &cksum);
}
return status;
const krb5_checksum *cksum, krb5_boolean *valid)
{
const struct krb5_cksumtypes *ctp;
+ krb5_cksumtype cksumtype;
krb5_crypto_iov iov;
krb5_error_code ret;
krb5_data cksum_data;
iov.flags = KRB5_CRYPTO_TYPE_DATA;
iov.data = *data;
- ctp = find_cksumtype(cksum->checksum_type);
+ /* A 0 checksum type means use the mandatory checksum. */
+ cksumtype = cksum->checksum_type;
+ if (cksumtype == 0 && key != NULL) {
+ ret = krb5int_c_mandatory_cksumtype(context, key->keyblock.enctype,
+ &cksumtype);
+ if (ret)
+ return ret;
+ }
+ ctp = find_cksumtype(cksumtype);
if (ctp == NULL)
return KRB5_BAD_ENCTYPE;