1/*
2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Portions Copyright (c) 2009 - 2010 Apple Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of KTH nor the names of its contributors may be
20 *    used to endorse or promote products derived from this software without
21 *    specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include "config.h"
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <errno.h>
42
43#include <krb5-types.h>
44
45#include <wind.h>
46#include <roken.h>
47#include <base64.h>
48
49#include <heimbase.h>
50
51#include "heimscram.h"
52#include "crypto-headers.h"
53
54#ifndef __APPLE_TARGET_EMBEDDED__
55#include <CommonCrypto/CommonKeyDerivation.h>
56#endif
57
58
59struct heim_scram_pair {
60    char type;
61    heim_scram_data data;
62};
63
64struct heim_scram_pairs {
65    int flags;
66#define SCRAM_PAIR_ALLOCATED 1
67#define SCRAM_ARRAY_ALLOCATED 2
68#define SCRAM_BINDINGS_YES 4
69#define SCRAM_BINDINGS_NO 8
70    struct heim_scram_pair *val;
71    size_t len;
72};
73
74typedef struct heim_scram_pairs heim_scram_pairs;
75
76struct heim_scram {
77    struct heim_scram_method_desc *method;
78    enum { CLIENT, SERVER } type;
79    heim_scram_data client1;
80    heim_scram_data server1;
81    /* generated */
82    heim_scram_data nonce;
83
84    /* server */
85    struct heim_scram_server *server;
86    void *ctx;
87
88    heim_scram_data user;
89
90    /* output */
91    heim_scram_data ClientProof;
92    heim_scram_data ServerSignature;
93    heim_scram_data SessionKey;
94};
95
96#include "heimscram-protos.h"
97
98int
99_heim_scram_parse(heim_scram_data *data, heim_scram_pairs **pd);
100
101int
102_heim_scram_unparse (
103	heim_scram_pairs */*d*/,
104	heim_scram_data */*out*/);
105
106void
107_heim_scram_pairs_free (heim_scram_pairs */*d*/);
108