625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce/*
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce SSSD
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce NSS crypto wrappers
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce Authors:
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce Jakub Hrozek <jhrozek@redhat.com>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce Copyright (C) Red Hat, Inc 2010
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce This program is free software; you can redistribute it and/or modify
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce it under the terms of the GNU General Public License as published by
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce the Free Software Foundation; either version 3 of the License, or
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce (at your option) any later version.
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce This program is distributed in the hope that it will be useful,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce but WITHOUT ANY WARRANTY; without even the implied warranty of
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce GNU General Public License for more details.
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce You should have received a copy of the GNU General Public License
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce along with this program. If not, see <http://www.gnu.org/licenses/>.
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce*/
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#include <nss.h>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#include <prerror.h>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#include <pk11func.h>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#include <base64.h>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#include <talloc.h>
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce#define MAKE_SECITEM(sdata, slen, sitem) do { \
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce (sitem)->type = (siBuffer); \
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce (sitem)->data = (sdata); \
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce (sitem)->len = (slen); \
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce} while(0)
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorcestruct sss_nss_crypto_ctx {
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce PK11SlotInfo *slot;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce PK11Context *ectx;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce PK11SymKey *keyobj;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce SECItem *sparam;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce SECItem *iv;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce SECItem *key;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce};
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorcestruct crypto_mech_data {
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce CK_MECHANISM_TYPE cipher;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce uint16_t keylen;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce uint16_t bsize;
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce};
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorceenum crypto_mech_op {
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce op_encrypt,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce op_decrypt,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce op_sign
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce};
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorceint nss_ctx_init(TALLOC_CTX *mem_ctx,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce struct crypto_mech_data *mech_props,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce uint8_t *key, int keylen,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce uint8_t *iv, int ivlen,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce struct sss_nss_crypto_ctx **_cctx);
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorceint nss_crypto_init(struct crypto_mech_data *mech_props,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce enum crypto_mech_op crypto_op,
625bb2ddf15e8f305a53afa44e87f2146fa930afSimo Sorce struct sss_nss_crypto_ctx *cctx);