1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3
* lib/crypto/crypto_length.c
5
* Copyright 2008 by the Massachusetts Institute of Technology.
8
* Export of this software from the United States of America may
9
* require a specific license from the United States Government.
10
* It is the responsibility of any person or organization contemplating
11
* export to obtain such a license before exporting.
13
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14
* distribute this software and its documentation for any purpose and
15
* without fee is hereby granted, provided that the above copyright
16
* notice appear in all copies and that both that copyright notice and
17
* this permission notice appear in supporting documentation, and that
18
* the name of M.I.T. not be used in advertising or publicity pertaining
19
* to distribution of the software without specific, written prior
20
* permission. Furthermore if you modify this software you must label
21
* your software as modified software and not distribute it in such a
22
* fashion that it might be confused with the original M.I.T. software.
23
* M.I.T. makes no representations about the suitability of
24
* this software for any purpose. It is provided "as is" without express
25
* or implied warranty.
32
krb5_error_code KRB5_CALLCONV
33
krb5_c_crypto_length(krb5_context context, krb5_enctype enctype,
34
krb5_cryptotype type, unsigned int *size)
36
const struct krb5_keytypes *ktp;
38
ktp = find_enctype(enctype);
40
return KRB5_BAD_ENCTYPE;
43
case KRB5_CRYPTO_TYPE_EMPTY:
44
case KRB5_CRYPTO_TYPE_SIGN_ONLY:
47
case KRB5_CRYPTO_TYPE_DATA:
48
*size = (size_t)~0; /* match Heimdal */
50
case KRB5_CRYPTO_TYPE_HEADER:
51
case KRB5_CRYPTO_TYPE_PADDING:
52
case KRB5_CRYPTO_TYPE_TRAILER:
53
case KRB5_CRYPTO_TYPE_CHECKSUM:
54
*size = ktp->crypto_length(ktp, type);
63
krb5_error_code KRB5_CALLCONV
64
krb5_c_padding_length(krb5_context context, krb5_enctype enctype,
65
size_t data_length, unsigned int *pad_length)
67
const struct krb5_keytypes *ktp;
69
ktp = find_enctype(enctype);
71
return KRB5_BAD_ENCTYPE;
73
*pad_length = krb5int_c_padding_length(ktp, data_length);
77
krb5_error_code KRB5_CALLCONV
78
krb5_c_crypto_length_iov(krb5_context context, krb5_enctype enctype,
79
krb5_crypto_iov *data, size_t num_data)
82
const struct krb5_keytypes *ktp;
83
unsigned int data_length = 0, pad_length;
84
krb5_crypto_iov *padding = NULL;
87
* XXX need to rejig internal interface so we can accurately
88
* report variable header lengths.
91
ktp = find_enctype(enctype);
93
return KRB5_BAD_ENCTYPE;
95
for (i = 0; i < num_data; i++) {
96
krb5_crypto_iov *iov = &data[i];
99
case KRB5_CRYPTO_TYPE_DATA:
100
data_length += iov->data.length;
102
case KRB5_CRYPTO_TYPE_PADDING:
108
case KRB5_CRYPTO_TYPE_HEADER:
109
case KRB5_CRYPTO_TYPE_TRAILER:
110
case KRB5_CRYPTO_TYPE_CHECKSUM:
111
iov->data.length = ktp->crypto_length(ktp, iov->flags);
113
case KRB5_CRYPTO_TYPE_EMPTY:
114
case KRB5_CRYPTO_TYPE_SIGN_ONLY:
120
pad_length = krb5int_c_padding_length(ktp, data_length);
121
if (pad_length != 0 && padding == NULL)
125
padding->data.length = pad_length;