~ubuntu-branches/ubuntu/lucid/krb5/lucid-updates

« back to all changes in this revision

Viewing changes to src/lib/crypto/krb/crypto_length.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2010-01-13 19:00:37 UTC
  • mfrom: (13.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100113190037-hrvrxs7cftafjotm
Tags: 1.8+dfsg~alpha1-4
* Add replaces to deal with moving files from krb5-multidev to
  libkrb5-dev, Closes: #565217 
* This is definitely the getting all the conflicts combinations right is
  tricky series of releases.  Sorry about the wasted cycles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
/*
 
3
 * lib/crypto/crypto_length.c
 
4
 *
 
5
 * Copyright 2008 by the Massachusetts Institute of Technology.
 
6
 * All Rights Reserved.
 
7
 *
 
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.
 
12
 *
 
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.
 
26
 */
 
27
 
 
28
#include "k5-int.h"
 
29
#include "etypes.h"
 
30
#include "aead.h"
 
31
 
 
32
krb5_error_code KRB5_CALLCONV
 
33
krb5_c_crypto_length(krb5_context context, krb5_enctype enctype,
 
34
                     krb5_cryptotype type, unsigned int *size)
 
35
{
 
36
    const struct krb5_keytypes *ktp;
 
37
 
 
38
    ktp = find_enctype(enctype);
 
39
    if (ktp == NULL)
 
40
        return KRB5_BAD_ENCTYPE;
 
41
 
 
42
    switch (type) {
 
43
    case KRB5_CRYPTO_TYPE_EMPTY:
 
44
    case KRB5_CRYPTO_TYPE_SIGN_ONLY:
 
45
        *size = 0;
 
46
        break;
 
47
    case KRB5_CRYPTO_TYPE_DATA:
 
48
        *size = (size_t)~0; /* match Heimdal */
 
49
        break;
 
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);
 
55
        break;
 
56
    default:
 
57
        return EINVAL;
 
58
    }
 
59
 
 
60
    return 0;
 
61
}
 
62
 
 
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)
 
66
{
 
67
    const struct krb5_keytypes *ktp;
 
68
 
 
69
    ktp = find_enctype(enctype);
 
70
    if (ktp == NULL)
 
71
        return KRB5_BAD_ENCTYPE;
 
72
 
 
73
    *pad_length = krb5int_c_padding_length(ktp, data_length);
 
74
    return 0;
 
75
}
 
76
 
 
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)
 
80
{
 
81
    size_t i;
 
82
    const struct krb5_keytypes *ktp;
 
83
    unsigned int data_length = 0, pad_length;
 
84
    krb5_crypto_iov *padding = NULL;
 
85
 
 
86
    /*
 
87
     * XXX need to rejig internal interface so we can accurately
 
88
     * report variable header lengths.
 
89
     */
 
90
 
 
91
    ktp = find_enctype(enctype);
 
92
    if (ktp == NULL)
 
93
        return KRB5_BAD_ENCTYPE;
 
94
 
 
95
    for (i = 0; i < num_data; i++) {
 
96
        krb5_crypto_iov *iov = &data[i];
 
97
 
 
98
        switch (iov->flags) {
 
99
        case KRB5_CRYPTO_TYPE_DATA:
 
100
            data_length += iov->data.length;
 
101
            break;
 
102
        case KRB5_CRYPTO_TYPE_PADDING:
 
103
            if (padding != NULL)
 
104
                return EINVAL;
 
105
 
 
106
            padding = iov;
 
107
            break;
 
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);
 
112
            break;
 
113
        case KRB5_CRYPTO_TYPE_EMPTY:
 
114
        case KRB5_CRYPTO_TYPE_SIGN_ONLY:
 
115
        default:
 
116
            break;
 
117
        }
 
118
    }
 
119
 
 
120
    pad_length = krb5int_c_padding_length(ktp, data_length);
 
121
    if (pad_length != 0 && padding == NULL)
 
122
        return EINVAL;
 
123
 
 
124
    if (padding != NULL)
 
125
        padding->data.length = pad_length;
 
126
 
 
127
    return 0;
 
128
}