Path: blob/main/crypto/krb5/src/plugins/preauth/spake/groups.h
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* plugins/preauth/spake/groups.h - SPAKE group interfaces */2/*3* Copyright (C) 2015 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132#ifndef GROUPS_H33#define GROUPS_H3435#include "k5-int.h"36#include "iana.h"3738typedef struct groupstate_st groupstate;39typedef struct groupdata_st groupdata;40typedef struct groupdef_st groupdef;4142struct groupdef_st {43const spake_iana *reg;4445/*46* Optional: create a per-group data object to allow more efficient keygen47* and result computations. Saving a reference to gdef is okay; its48* lifetime will always be longer than the resulting object.49*/50krb5_error_code (*init)(krb5_context context, const groupdef *gdef,51groupdata **gdata_out);5253/* Optional: release a group data object. */54void (*fini)(groupdata *gdata);5556/*57* Mandatory: generate a random private scalar (x or y) and a public58* element (T or S), using wbytes for the w value. If use_m is true, use59* the M element (generating T); otherwise use the N element (generating60* S). wbytes and priv_out have length reg->mult_len; pub_out has length61* reg->elem_len. priv_out and pub_out are caller-allocated.62*/63krb5_error_code (*keygen)(krb5_context context, groupdata *gdata,64const uint8_t *wbytes, krb5_boolean use_m,65uint8_t *priv_out, uint8_t *pub_out);6667/*68* Mandatory: compute K given a private scalar (x or y) and the other69* party's public element (S or T), using wbytes for the w value. If use_m70* is true, use the M element (computing K from y and T); otherwise use the71* N element (computing K from x and S). wbytes and ourpriv have length72* reg->mult_len; theirpub and elem_out have length reg->elem_len.73* elem_out is caller-allocated.74*/75krb5_error_code (*result)(krb5_context context, groupdata *gdata,76const uint8_t *wbytes, const uint8_t *ourpriv,77const uint8_t *theirpub, krb5_boolean use_m,78uint8_t *elem_out);7980/*81* Mandatory: compute the group's specified hash function over datas (with82* ndata elements), placing the result in result_out. result_out is83* caller-allocated with length reg->hash_len.84*/85krb5_error_code (*hash)(krb5_context context, groupdata *gdata,86const krb5_data *datas, size_t ndata,87uint8_t *result_out);88};8990/* Initialize an object which holds group configuration and pre-computation91* state for each group. is_kdc is true for KDCs, false for clients. */92krb5_error_code group_init_state(krb5_context context, krb5_boolean is_kdc,93groupstate **out);9495/* Release resources held by gstate. */96void group_free_state(groupstate *gstate);9798/* Return true if group is permitted by configuration. */99krb5_boolean group_is_permitted(groupstate *gstate, int32_t group);100101/* Set *list_out and *count_out to the list of groups permitted by102* configuration. */103void group_get_permitted(groupstate *gstate, int32_t **list_out,104int32_t *count_out);105106/* Return the KDC optimistic challenge group if one is configured. Valid for107* KDC groupstate objects only. */108krb5_int32 group_optimistic_challenge(groupstate *gstate);109110/* Set *len_out to the multiplier length for group. */111krb5_error_code group_mult_len(int32_t group, size_t *len_out);112113/*114* Generate a SPAKE private scalar (x or y) and public element (T or S), given115* an input multiplier wbytes. Use constant M if gstate is a KDC groupstate116* object, N if it is a client object. Allocate storage and place the results117* in *priv_out and *pub_out.118*/119krb5_error_code group_keygen(krb5_context context, groupstate *gstate,120int32_t group, const krb5_data *wbytes,121krb5_data *priv_out, krb5_data *pub_out);122123/*124* Compute the SPAKE result K from our private scalar (x or y) and their public125* key (S or T), deriving the input scalar w from ikey. Use the other party's126* constant, N if gstate is a KDC groupstate object or M if it is a client127* object. Allocate storage and place the result in *spakeresult_out.128*/129krb5_error_code group_result(krb5_context context, groupstate *gstate,130int32_t group, const krb5_data *wbytes,131const krb5_data *ourpriv,132const krb5_data *theirpub,133krb5_data *spakeresult_out);134135/* Set *result_out to the hash output length for group. */136krb5_error_code group_hash_len(int32_t group, size_t *result_out);137138/*139* Compute the group's specified hash function over dlist (with ndata140* elements). result_out is caller-allocated with enough bytes for the hash141* output as given by group_hash_len().142*/143krb5_error_code group_hash(krb5_context context, groupstate *gstate,144int32_t group, const krb5_data *dlist, size_t ndata,145uint8_t *result_out);146147#endif /* GROUPS_H */148149150