Path: blob/master/drivers/crypto/amcc/crypto4xx_sa.c
15111 views
/**1* AMCC SoC PPC4xx Crypto Driver2*3* Copyright (c) 2008 Applied Micro Circuits Corporation.4* All rights reserved. James Hsiao <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* @file crypto4xx_sa.c17*18* This file implements the security context19* associate format.20*/21#include <linux/kernel.h>22#include <linux/module.h>23#include <linux/moduleparam.h>24#include <linux/mod_devicetable.h>25#include <linux/interrupt.h>26#include <linux/spinlock_types.h>27#include <linux/highmem.h>28#include <linux/scatterlist.h>29#include <linux/crypto.h>30#include <crypto/algapi.h>31#include <crypto/des.h>32#include "crypto4xx_reg_def.h"33#include "crypto4xx_sa.h"34#include "crypto4xx_core.h"3536u32 get_dynamic_sa_offset_iv_field(struct crypto4xx_ctx *ctx)37{38u32 offset;39union dynamic_sa_contents cts;4041if (ctx->direction == DIR_INBOUND)42cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;43else44cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;45offset = cts.bf.key_size46+ cts.bf.inner_size47+ cts.bf.outer_size48+ cts.bf.spi49+ cts.bf.seq_num050+ cts.bf.seq_num151+ cts.bf.seq_num_mask052+ cts.bf.seq_num_mask153+ cts.bf.seq_num_mask254+ cts.bf.seq_num_mask3;5556return sizeof(struct dynamic_sa_ctl) + offset * 4;57}5859u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)60{61u32 offset;62union dynamic_sa_contents cts;6364if (ctx->direction == DIR_INBOUND)65cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;66else67cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;68offset = cts.bf.key_size69+ cts.bf.inner_size70+ cts.bf.outer_size71+ cts.bf.spi72+ cts.bf.seq_num073+ cts.bf.seq_num174+ cts.bf.seq_num_mask075+ cts.bf.seq_num_mask176+ cts.bf.seq_num_mask277+ cts.bf.seq_num_mask378+ cts.bf.iv079+ cts.bf.iv180+ cts.bf.iv281+ cts.bf.iv3;8283return sizeof(struct dynamic_sa_ctl) + offset * 4;84}8586u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)87{88union dynamic_sa_contents cts;8990if (ctx->direction == DIR_INBOUND)91cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;92else93cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;94return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;95}9697u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)98{99union dynamic_sa_contents cts;100101if (ctx->direction == DIR_INBOUND)102cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;103else104cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;105106return sizeof(struct dynamic_sa_ctl);107}108109110