2
0
forked from Ivasoft/openwrt

rename target/linux/generic-2.6 to generic

SVN-Revision: 21952
This commit is contained in:
Felix Fietkau
2010-06-26 20:42:58 +00:00
parent 6117c04c94
commit da1bb88a2b
1042 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
/* mvAes.h v2.0 August '99
* Reference ANSI C code
*/
/* AES Cipher header file for ANSI C Submissions
Lawrence E. Bassham III
Computer Security Division
National Institute of Standards and Technology
April 15, 1998
This sample is to assist implementers developing to the Cryptographic
API Profile for AES Candidate Algorithm Submissions. Please consult this
document as a cross-reference.
ANY CHANGES, WHERE APPROPRIATE, TO INFORMATION PROVIDED IN THIS FILE
MUST BE DOCUMENTED. CHANGES ARE ONLY APPROPRIATE WHERE SPECIFIED WITH
THE STRING "CHANGE POSSIBLE". FUNCTION CALLS AND THEIR PARAMETERS CANNOT
BE CHANGED. STRUCTURES CAN BE ALTERED TO ALLOW IMPLEMENTERS TO INCLUDE
IMPLEMENTATION SPECIFIC INFORMATION.
*/
/* Includes:
Standard include files
*/
#include "mvOs.h"
/* Error Codes - CHANGE POSSIBLE: inclusion of additional error codes */
/* Key direction is invalid, e.g., unknown value */
#define AES_BAD_KEY_DIR -1
/* Key material not of correct length */
#define AES_BAD_KEY_MAT -2
/* Key passed is not valid */
#define AES_BAD_KEY_INSTANCE -3
/* Params struct passed to cipherInit invalid */
#define AES_BAD_CIPHER_MODE -4
/* Cipher in wrong state (e.g., not initialized) */
#define AES_BAD_CIPHER_STATE -5
#define AES_BAD_CIPHER_INSTANCE -7
/* Function protoypes */
/* CHANGED: makeKey(): parameter blockLen added
this parameter is absolutely necessary if you want to
setup the round keys in a variable block length setting
cipherInit(): parameter blockLen added (for obvious reasons)
*/
int aesMakeKey(MV_U8 *expandedKey, MV_U8 *keyMaterial, int keyLen, int blockLen);
int aesBlockEncrypt128(MV_U8 mode, MV_U8 *IV, MV_U8 *expandedKey, int keyLen,
MV_U32 *plain, int numBlocks, MV_U32 *cipher);
int aesBlockDecrypt128(MV_U8 mode, MV_U8 *IV, MV_U8 *expandedKey, int keyLen,
MV_U32 *plain, int numBlocks, MV_U32 *cipher);

View File

@@ -0,0 +1,317 @@
/* rijndael-alg-ref.c v2.0 August '99
* Reference ANSI C code
* authors: Paulo Barreto
* Vincent Rijmen, K.U.Leuven
*
* This code is placed in the public domain.
*/
#include "mvOs.h"
#include "mvAesAlg.h"
#include "mvAesBoxes.dat"
MV_U8 mul1(MV_U8 aa, MV_U8 bb);
void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC);
void ShiftRow128Enc(MV_U8 a[4][MAXBC]);
void ShiftRow128Dec(MV_U8 a[4][MAXBC]);
void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256]);
void MixColumn(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC]);
void InvMixColumn(MV_U8 a[4][MAXBC]);
#define mul(aa, bb) (mask[bb] & Alogtable[aa + Logtable[bb]])
MV_U8 mul1(MV_U8 aa, MV_U8 bb)
{
return mask[bb] & Alogtable[aa + Logtable[bb]];
}
void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC)
{
/* Exor corresponding text input and round key input bytes
*/
((MV_U32*)(&(a[0][0])))[0] ^= ((MV_U32*)(&(rk[0][0])))[0];
((MV_U32*)(&(a[1][0])))[0] ^= ((MV_U32*)(&(rk[1][0])))[0];
((MV_U32*)(&(a[2][0])))[0] ^= ((MV_U32*)(&(rk[2][0])))[0];
((MV_U32*)(&(a[3][0])))[0] ^= ((MV_U32*)(&(rk[3][0])))[0];
}
void ShiftRow128Enc(MV_U8 a[4][MAXBC]) {
/* Row 0 remains unchanged
* The other three rows are shifted a variable amount
*/
MV_U8 tmp[MAXBC];
tmp[0] = a[1][1];
tmp[1] = a[1][2];
tmp[2] = a[1][3];
tmp[3] = a[1][0];
((MV_U32*)(&(a[1][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[1][0] = tmp[0];
a[1][1] = tmp[1];
a[1][2] = tmp[2];
a[1][3] = tmp[3];
*/
tmp[0] = a[2][2];
tmp[1] = a[2][3];
tmp[2] = a[2][0];
tmp[3] = a[2][1];
((MV_U32*)(&(a[2][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[2][0] = tmp[0];
a[2][1] = tmp[1];
a[2][2] = tmp[2];
a[2][3] = tmp[3];
*/
tmp[0] = a[3][3];
tmp[1] = a[3][0];
tmp[2] = a[3][1];
tmp[3] = a[3][2];
((MV_U32*)(&(a[3][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[3][0] = tmp[0];
a[3][1] = tmp[1];
a[3][2] = tmp[2];
a[3][3] = tmp[3];
*/
}
void ShiftRow128Dec(MV_U8 a[4][MAXBC]) {
/* Row 0 remains unchanged
* The other three rows are shifted a variable amount
*/
MV_U8 tmp[MAXBC];
tmp[0] = a[1][3];
tmp[1] = a[1][0];
tmp[2] = a[1][1];
tmp[3] = a[1][2];
((MV_U32*)(&(a[1][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[1][0] = tmp[0];
a[1][1] = tmp[1];
a[1][2] = tmp[2];
a[1][3] = tmp[3];
*/
tmp[0] = a[2][2];
tmp[1] = a[2][3];
tmp[2] = a[2][0];
tmp[3] = a[2][1];
((MV_U32*)(&(a[2][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[2][0] = tmp[0];
a[2][1] = tmp[1];
a[2][2] = tmp[2];
a[2][3] = tmp[3];
*/
tmp[0] = a[3][1];
tmp[1] = a[3][2];
tmp[2] = a[3][3];
tmp[3] = a[3][0];
((MV_U32*)(&(a[3][0])))[0] = ((MV_U32*)(&(tmp[0])))[0];
/*
a[3][0] = tmp[0];
a[3][1] = tmp[1];
a[3][2] = tmp[2];
a[3][3] = tmp[3];
*/
}
void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256]) {
/* Replace every byte of the input by the byte at that place
* in the nonlinear S-box
*/
int i, j;
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++) a[i][j] = box[a[i][j]] ;
}
void MixColumn(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC]) {
/* Mix the four bytes of every column in a linear way
*/
MV_U8 b[4][MAXBC];
int i, j;
for(j = 0; j < 4; j++){
b[0][j] = mul(25,a[0][j]) ^ mul(1,a[1][j]) ^ a[2][j] ^ a[3][j];
b[1][j] = mul(25,a[1][j]) ^ mul(1,a[2][j]) ^ a[3][j] ^ a[0][j];
b[2][j] = mul(25,a[2][j]) ^ mul(1,a[3][j]) ^ a[0][j] ^ a[1][j];
b[3][j] = mul(25,a[3][j]) ^ mul(1,a[0][j]) ^ a[1][j] ^ a[2][j];
}
for(i = 0; i < 4; i++)
/*for(j = 0; j < BC; j++) a[i][j] = b[i][j];*/
((MV_U32*)(&(a[i][0])))[0] = ((MV_U32*)(&(b[i][0])))[0] ^ ((MV_U32*)(&(rk[i][0])))[0];;
}
void InvMixColumn(MV_U8 a[4][MAXBC]) {
/* Mix the four bytes of every column in a linear way
* This is the opposite operation of Mixcolumn
*/
MV_U8 b[4][MAXBC];
int i, j;
for(j = 0; j < 4; j++){
b[0][j] = mul(223,a[0][j]) ^ mul(104,a[1][j]) ^ mul(238,a[2][j]) ^ mul(199,a[3][j]);
b[1][j] = mul(223,a[1][j]) ^ mul(104,a[2][j]) ^ mul(238,a[3][j]) ^ mul(199,a[0][j]);
b[2][j] = mul(223,a[2][j]) ^ mul(104,a[3][j]) ^ mul(238,a[0][j]) ^ mul(199,a[1][j]);
b[3][j] = mul(223,a[3][j]) ^ mul(104,a[0][j]) ^ mul(238,a[1][j]) ^ mul(199,a[2][j]);
}
for(i = 0; i < 4; i++)
/*for(j = 0; j < BC; j++) a[i][j] = b[i][j];*/
((MV_U32*)(&(a[i][0])))[0] = ((MV_U32*)(&(b[i][0])))[0];
}
int rijndaelKeySched (MV_U8 k[4][MAXKC], int keyBits, int blockBits, MV_U8 W[MAXROUNDS+1][4][MAXBC])
{
/* Calculate the necessary round keys
* The number of calculations depends on keyBits and blockBits
*/
int KC, BC, ROUNDS;
int i, j, t, rconpointer = 0;
MV_U8 tk[4][MAXKC];
switch (keyBits) {
case 128: KC = 4; break;
case 192: KC = 6; break;
case 256: KC = 8; break;
default : return (-1);
}
switch (blockBits) {
case 128: BC = 4; break;
case 192: BC = 6; break;
case 256: BC = 8; break;
default : return (-2);
}
switch (keyBits >= blockBits ? keyBits : blockBits) {
case 128: ROUNDS = 10; break;
case 192: ROUNDS = 12; break;
case 256: ROUNDS = 14; break;
default : return (-3); /* this cannot happen */
}
for(j = 0; j < KC; j++)
for(i = 0; i < 4; i++)
tk[i][j] = k[i][j];
t = 0;
/* copy values into round key array */
for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++)
for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j];
while (t < (ROUNDS+1)*BC) { /* while not enough round key material calculated */
/* calculate new values */
for(i = 0; i < 4; i++)
tk[i][0] ^= S[tk[(i+1)%4][KC-1]];
tk[0][0] ^= rcon[rconpointer++];
if (KC != 8)
for(j = 1; j < KC; j++)
for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
else {
for(j = 1; j < KC/2; j++)
for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
for(i = 0; i < 4; i++) tk[i][KC/2] ^= S[tk[i][KC/2 - 1]];
for(j = KC/2 + 1; j < KC; j++)
for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
}
/* copy values into round key array */
for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++)
for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j];
}
return 0;
}
int rijndaelEncrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds)
{
/* Encryption of one block.
*/
int r, BC, ROUNDS;
BC = 4;
ROUNDS = rounds;
/* begin with a key addition
*/
KeyAddition(a,rk[0],BC);
/* ROUNDS-1 ordinary rounds
*/
for(r = 1; r < ROUNDS; r++) {
Substitution(a,S);
ShiftRow128Enc(a);
MixColumn(a, rk[r]);
/*KeyAddition(a,rk[r],BC);*/
}
/* Last round is special: there is no MixColumn
*/
Substitution(a,S);
ShiftRow128Enc(a);
KeyAddition(a,rk[ROUNDS],BC);
return 0;
}
int rijndaelDecrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds)
{
int r, BC, ROUNDS;
BC = 4;
ROUNDS = rounds;
/* To decrypt: apply the inverse operations of the encrypt routine,
* in opposite order
*
* (KeyAddition is an involution: it 's equal to its inverse)
* (the inverse of Substitution with table S is Substitution with the inverse table of S)
* (the inverse of Shiftrow is Shiftrow over a suitable distance)
*/
/* First the special round:
* without InvMixColumn
* with extra KeyAddition
*/
KeyAddition(a,rk[ROUNDS],BC);
ShiftRow128Dec(a);
Substitution(a,Si);
/* ROUNDS-1 ordinary rounds
*/
for(r = ROUNDS-1; r > 0; r--) {
KeyAddition(a,rk[r],BC);
InvMixColumn(a);
ShiftRow128Dec(a);
Substitution(a,Si);
}
/* End with the extra key addition
*/
KeyAddition(a,rk[0],BC);
return 0;
}

View File

@@ -0,0 +1,19 @@
/* rijndael-alg-ref.h v2.0 August '99
* Reference ANSI C code
* authors: Paulo Barreto
* Vincent Rijmen, K.U.Leuven
*/
#ifndef __RIJNDAEL_ALG_H
#define __RIJNDAEL_ALG_H
#define MAXBC (128/32)
#define MAXKC (256/32)
#define MAXROUNDS 14
int rijndaelKeySched (MV_U8 k[4][MAXKC], int keyBits, int blockBits, MV_U8 rk[MAXROUNDS+1][4][MAXBC]);
int rijndaelEncrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds);
int rijndaelDecrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds);
#endif /* __RIJNDAEL_ALG_H */

View File

@@ -0,0 +1,312 @@
/* rijndael-api-ref.c v2.1 April 2000
* Reference ANSI C code
* authors: v2.0 Paulo Barreto
* Vincent Rijmen, K.U.Leuven
* v2.1 Vincent Rijmen, K.U.Leuven
*
* This code is placed in the public domain.
*/
#include "mvOs.h"
#include "mvAes.h"
#include "mvAesAlg.h"
/* Defines:
Add any additional defines you need
*/
#define MODE_ECB 1 /* Are we ciphering in ECB mode? */
#define MODE_CBC 2 /* Are we ciphering in CBC mode? */
#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
int aesMakeKey(MV_U8 *expandedKey, MV_U8 *keyMaterial, int keyLen, int blockLen)
{
MV_U8 W[MAXROUNDS+1][4][MAXBC];
MV_U8 k[4][MAXKC];
MV_U8 j;
int i, rounds, KC;
if (expandedKey == NULL)
{
return AES_BAD_KEY_INSTANCE;
}
if (!((keyLen == 128) || (keyLen == 192) || (keyLen == 256)))
{
return AES_BAD_KEY_MAT;
}
if (keyMaterial == NULL)
{
return AES_BAD_KEY_MAT;
}
/* initialize key schedule: */
for(i=0; i<keyLen/8; i++)
{
j = keyMaterial[i];
k[i % 4][i / 4] = j;
}
rijndaelKeySched (k, keyLen, blockLen, W);
#ifdef MV_AES_DEBUG
{
MV_U8* pW = &W[0][0][0];
int x;
mvOsPrintf("Expended Key: size = %d\n", sizeof(W));
for(i=0; i<sizeof(W); i++)
{
mvOsPrintf("%02x ", pW[i]);
}
for(i=0; i<MAXROUNDS+1; i++)
{
mvOsPrintf("\n Round #%02d: ", i);
for(x=0; x<MAXBC; x++)
{
mvOsPrintf("%02x%02x%02x%02x ",
W[i][0][x], W[i][1][x], W[i][2][x], W[i][3][x]);
}
mvOsPrintf("\n");
}
}
#endif /* MV_AES_DEBUG */
switch (keyLen)
{
case 128:
rounds = 10;
KC = 4;
break;
case 192:
rounds = 12;
KC = 6;
break;
case 256:
rounds = 14;
KC = 8;
break;
default :
return (-1);
}
for(i=0; i<MAXBC; i++)
{
for(j=0; j<4; j++)
{
expandedKey[i*4+j] = W[rounds][j][i];
}
}
for(; i<KC; i++)
{
for(j=0; j<4; j++)
{
expandedKey[i*4+j] = W[rounds-1][j][i+MAXBC-KC];
}
}
return 0;
}
int aesBlockEncrypt128(MV_U8 mode, MV_U8 *IV, MV_U8 *expandedKey, int keyLen,
MV_U32 *plain, int numBlocks, MV_U32 *cipher)
{
int i, j, t;
MV_U8 block[4][MAXBC];
int rounds;
char *input, *outBuffer;
input = (char*)plain;
outBuffer = (char*)cipher;
/* check parameter consistency: */
if( (expandedKey == NULL) || ((keyLen != 128) && (keyLen != 192) && (keyLen != 256)))
{
return AES_BAD_KEY_MAT;
}
if ((mode != MODE_ECB && mode != MODE_CBC))
{
return AES_BAD_CIPHER_STATE;
}
switch (keyLen)
{
case 128: rounds = 10; break;
case 192: rounds = 12; break;
case 256: rounds = 14; break;
default : return (-3); /* this cannot happen */
}
switch (mode)
{
case MODE_ECB:
for (i = 0; i < numBlocks; i++)
{
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
/* parse input stream into rectangular array */
block[t][j] = input[16*i+4*j+t] & 0xFF;
}
rijndaelEncrypt128(block, (MV_U8 (*)[4][MAXBC])expandedKey, rounds);
for (j = 0; j < 4; j++)
{
/* parse rectangular array into output ciphertext bytes */
for(t = 0; t < 4; t++)
outBuffer[16*i+4*j+t] = (MV_U8) block[t][j];
}
}
break;
case MODE_CBC:
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
/* parse initial value into rectangular array */
block[t][j] = IV[t+4*j] & 0xFF;
}
for (i = 0; i < numBlocks; i++)
{
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
/* parse input stream into rectangular array and exor with
IV or the previous ciphertext */
block[t][j] ^= input[16*i+4*j+t] & 0xFF;
}
rijndaelEncrypt128(block, (MV_U8 (*)[4][MAXBC])expandedKey, rounds);
for (j = 0; j < 4; j++)
{
/* parse rectangular array into output ciphertext bytes */
for(t = 0; t < 4; t++)
outBuffer[16*i+4*j+t] = (MV_U8) block[t][j];
}
}
break;
default: return AES_BAD_CIPHER_STATE;
}
return 0;
}
int aesBlockDecrypt128(MV_U8 mode, MV_U8 *IV, MV_U8 *expandedKey, int keyLen,
MV_U32 *srcData, int numBlocks, MV_U32 *dstData)
{
int i, j, t;
MV_U8 block[4][MAXBC];
MV_U8 iv[4][MAXBC];
int rounds;
char *input, *outBuffer;
input = (char*)srcData;
outBuffer = (char*)dstData;
if (expandedKey == NULL)
{
return AES_BAD_KEY_MAT;
}
/* check parameter consistency: */
if (keyLen != 128 && keyLen != 192 && keyLen != 256)
{
return AES_BAD_KEY_MAT;
}
if ((mode != MODE_ECB && mode != MODE_CBC))
{
return AES_BAD_CIPHER_STATE;
}
switch (keyLen)
{
case 128: rounds = 10; break;
case 192: rounds = 12; break;
case 256: rounds = 14; break;
default : return (-3); /* this cannot happen */
}
switch (mode)
{
case MODE_ECB:
for (i = 0; i < numBlocks; i++)
{
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
{
/* parse input stream into rectangular array */
block[t][j] = input[16*i+4*j+t] & 0xFF;
}
}
rijndaelDecrypt128(block, (MV_U8 (*)[4][MAXBC])expandedKey, rounds);
for (j = 0; j < 4; j++)
{
/* parse rectangular array into output ciphertext bytes */
for(t = 0; t < 4; t++)
outBuffer[16*i+4*j+t] = (MV_U8) block[t][j];
}
}
break;
case MODE_CBC:
/* first block */
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
{
/* parse input stream into rectangular array */
block[t][j] = input[4*j+t] & 0xFF;
iv[t][j] = block[t][j];
}
}
rijndaelDecrypt128(block, (MV_U8 (*)[4][MAXBC])expandedKey, rounds);
for (j = 0; j < 4; j++)
{
/* exor the IV and parse rectangular array into output ciphertext bytes */
for(t = 0; t < 4; t++)
{
outBuffer[4*j+t] = (MV_U8) (block[t][j] ^ IV[t+4*j]);
IV[t+4*j] = iv[t][j];
}
}
/* next blocks */
for (i = 1; i < numBlocks; i++)
{
for (j = 0; j < 4; j++)
{
for(t = 0; t < 4; t++)
{
/* parse input stream into rectangular array */
iv[t][j] = input[16*i+4*j+t] & 0xFF;
block[t][j] = iv[t][j];
}
}
rijndaelDecrypt128(block, (MV_U8 (*)[4][MAXBC])expandedKey, rounds);
for (j = 0; j < 4; j++)
{
/* exor previous ciphertext block and parse rectangular array
into output ciphertext bytes */
for(t = 0; t < 4; t++)
{
outBuffer[16*i+4*j+t] = (MV_U8) (block[t][j] ^ IV[t+4*j]);
IV[t+4*j] = iv[t][j];
}
}
}
break;
default: return AES_BAD_CIPHER_STATE;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,412 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
/*******************************************************************************
* mvCesa.h - Header File for Cryptographic Engines and Security Accelerator
*
* DESCRIPTION:
* This header file contains macros typedefs and function declaration for
* the Marvell Cryptographic Engines and Security Accelerator.
*
*******************************************************************************/
#ifndef __mvCesa_h__
#define __mvCesa_h__
#include "mvOs.h"
#include "mvCommon.h"
#include "mvDebug.h"
#include "ctrlEnv/mvCtrlEnvSpec.h"
#include "cesa/mvMD5.h"
#include "cesa/mvSHA1.h"
#include "cesa/mvCesa.h"
#include "cesa/AES/mvAes.h"
#include "mvSysHwConfig.h"
#ifdef MV_INCLUDE_IDMA
#include "idma/mvIdma.h"
#include "idma/mvIdmaRegs.h"
#else
/* Redefine MV_DMA_DESC structure */
typedef struct _mvDmaDesc
{
MV_U32 byteCnt; /* The total number of bytes to transfer */
MV_U32 phySrcAdd; /* The physical source address */
MV_U32 phyDestAdd; /* The physical destination address */
MV_U32 phyNextDescPtr; /* If we are using chain mode DMA transfer, */
/* then this pointer should point to the */
/* physical address of the next descriptor, */
/* otherwise it should be NULL. */
}MV_DMA_DESC;
#endif /* MV_INCLUDE_IDMA */
#include "cesa/mvCesaRegs.h"
#define MV_CESA_AUTH_BLOCK_SIZE 64 /* bytes */
#define MV_CESA_MD5_DIGEST_SIZE 16 /* bytes */
#define MV_CESA_SHA1_DIGEST_SIZE 20 /* bytes */
#define MV_CESA_MAX_DIGEST_SIZE MV_CESA_SHA1_DIGEST_SIZE
#define MV_CESA_DES_KEY_LENGTH 8 /* bytes = 64 bits */
#define MV_CESA_3DES_KEY_LENGTH 24 /* bytes = 192 bits */
#define MV_CESA_AES_128_KEY_LENGTH 16 /* bytes = 128 bits */
#define MV_CESA_AES_192_KEY_LENGTH 24 /* bytes = 192 bits */
#define MV_CESA_AES_256_KEY_LENGTH 32 /* bytes = 256 bits */
#define MV_CESA_MAX_CRYPTO_KEY_LENGTH MV_CESA_AES_256_KEY_LENGTH
#define MV_CESA_DES_BLOCK_SIZE 8 /* bytes = 64 bits */
#define MV_CESA_3DES_BLOCK_SIZE 8 /* bytes = 64 bits */
#define MV_CESA_AES_BLOCK_SIZE 16 /* bytes = 128 bits */
#define MV_CESA_MAX_IV_LENGTH MV_CESA_AES_BLOCK_SIZE
#define MV_CESA_MAX_MAC_KEY_LENGTH 64 /* bytes */
typedef struct
{
MV_U8 cryptoKey[MV_CESA_MAX_CRYPTO_KEY_LENGTH];
MV_U8 macKey[MV_CESA_MAX_MAC_KEY_LENGTH];
MV_CESA_OPERATION operation;
MV_CESA_DIRECTION direction;
MV_CESA_CRYPTO_ALG cryptoAlgorithm;
MV_CESA_CRYPTO_MODE cryptoMode;
MV_U8 cryptoKeyLength;
MV_CESA_MAC_MODE macMode;
MV_U8 macKeyLength;
MV_U8 digestSize;
} MV_CESA_OPEN_SESSION;
typedef struct
{
MV_BUF_INFO *pFrags;
MV_U16 numFrags;
MV_U16 mbufSize;
} MV_CESA_MBUF;
typedef struct
{
void* pReqPrv; /* instead of reqId */
MV_U32 retCode;
MV_16 sessionId;
} MV_CESA_RESULT;
typedef void (*MV_CESA_CALLBACK) (MV_CESA_RESULT* pResult);
typedef struct
{
void* pReqPrv; /* instead of reqId */
MV_CESA_MBUF* pSrc;
MV_CESA_MBUF* pDst;
MV_CESA_CALLBACK* pFuncCB;
MV_16 sessionId;
MV_U16 ivFromUser;
MV_U16 ivOffset;
MV_U16 cryptoOffset;
MV_U16 cryptoLength;
MV_U16 digestOffset;
MV_U16 macOffset;
MV_U16 macLength;
MV_BOOL skipFlush;
} MV_CESA_COMMAND;
MV_STATUS mvCesaHalInit (int numOfSession, int queueDepth, char* pSramBase, MV_U32 cryptEngBase, void *osHandle);
MV_STATUS mvCesaFinish (void);
MV_STATUS mvCesaSessionOpen(MV_CESA_OPEN_SESSION *pSession, short* pSid);
MV_STATUS mvCesaSessionClose(short sid);
MV_STATUS mvCesaCryptoIvSet(MV_U8* pIV, int ivSize);
MV_STATUS mvCesaAction (MV_CESA_COMMAND* pCmd);
MV_U32 mvCesaInProcessGet(void);
MV_STATUS mvCesaReadyDispatch(void);
MV_STATUS mvCesaReadyGet(MV_CESA_RESULT* pResult);
MV_BOOL mvCesaIsReady(void);
int mvCesaMbufOffset(MV_CESA_MBUF* pMbuf, int offset, int* pBufOffset);
MV_STATUS mvCesaCopyFromMbuf(MV_U8* pDst, MV_CESA_MBUF* pSrcMbuf,
int offset, int size);
MV_STATUS mvCesaCopyToMbuf(MV_U8* pSrc, MV_CESA_MBUF* pDstMbuf,
int offset, int size);
MV_STATUS mvCesaMbufCopy(MV_CESA_MBUF* pMbufDst, int dstMbufOffset,
MV_CESA_MBUF* pMbufSrc, int srcMbufOffset, int size);
/********** Debug functions ********/
void mvCesaDebugMbuf(const char* str, MV_CESA_MBUF *pMbuf, int offset, int size);
void mvCesaDebugSA(short sid, int mode);
void mvCesaDebugStats(void);
void mvCesaDebugStatsClear(void);
void mvCesaDebugRegs(void);
void mvCesaDebugStatus(void);
void mvCesaDebugQueue(int mode);
void mvCesaDebugSram(int mode);
void mvCesaDebugSAD(int mode);
/******** CESA Private definitions ********/
#if (MV_CESA_VERSION >= 2)
#if (MV_CACHE_COHERENCY == MV_CACHE_COHER_SW)
#define MV_CESA_TDMA_CTRL_VALUE MV_CESA_TDMA_DST_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
| MV_CESA_TDMA_SRC_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
| MV_CESA_TDMA_OUTSTAND_READ_EN_MASK \
| MV_CESA_TDMA_NO_BYTE_SWAP_MASK \
| MV_CESA_TDMA_ENABLE_MASK
#else
#define MV_CESA_TDMA_CTRL_VALUE MV_CESA_TDMA_DST_BURST_MASK(MV_CESA_TDMA_BURST_32B) \
| MV_CESA_TDMA_SRC_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
/*| MV_CESA_TDMA_OUTSTAND_READ_EN_MASK */\
| MV_CESA_TDMA_ENABLE_MASK
#endif
#else
#define MV_CESA_IDMA_CTRL_LOW_VALUE ICCLR_DST_BURST_LIM_128BYTE \
| ICCLR_SRC_BURST_LIM_128BYTE \
| ICCLR_INT_MODE_MASK \
| ICCLR_BLOCK_MODE \
| ICCLR_CHAN_ENABLE \
| ICCLR_DESC_MODE_16M
#endif /* MV_CESA_VERSION >= 2 */
#define MV_CESA_MAX_PKT_SIZE (64 * 1024)
#define MV_CESA_MAX_MBUF_FRAGS 20
#define MV_CESA_MAX_REQ_FRAGS ( (MV_CESA_MAX_PKT_SIZE / MV_CESA_MAX_BUF_SIZE) + 1)
#define MV_CESA_MAX_DMA_DESC (MV_CESA_MAX_MBUF_FRAGS*2 + 5)
#define MAX_CESA_CHAIN_LENGTH 20
typedef enum
{
MV_CESA_IDLE = 0,
MV_CESA_PENDING,
MV_CESA_PROCESS,
MV_CESA_READY,
#if (MV_CESA_VERSION >= 3)
MV_CESA_CHAIN,
#endif
} MV_CESA_STATE;
/* Session database */
/* Map of Key materials of the session in SRAM.
* Each field must be 8 byte aligned
* Total size: 32 + 24 + 24 = 80 bytes
*/
typedef struct
{
MV_U8 cryptoKey[MV_CESA_MAX_CRYPTO_KEY_LENGTH];
MV_U8 macInnerIV[MV_CESA_MAX_DIGEST_SIZE];
MV_U8 reservedInner[4];
MV_U8 macOuterIV[MV_CESA_MAX_DIGEST_SIZE];
MV_U8 reservedOuter[4];
} MV_CESA_SRAM_SA;
typedef struct
{
MV_CESA_SRAM_SA* pSramSA;
MV_U32 config;
MV_U8 cryptoKeyLength;
MV_U8 cryptoIvSize;
MV_U8 cryptoBlockSize;
MV_U8 digestSize;
MV_U8 macKeyLength;
MV_U8 valid;
MV_U8 ctrMode;
MV_U32 count;
} MV_CESA_SA;
/* DMA list management */
typedef struct
{
MV_DMA_DESC* pDmaFirst;
MV_DMA_DESC* pDmaLast;
} MV_CESA_DMA;
typedef struct
{
MV_U8 numFrag;
MV_U8 nextFrag;
int bufOffset;
int cryptoSize;
int macSize;
int newDigestOffset;
MV_U8 orgDigest[MV_CESA_MAX_DIGEST_SIZE];
} MV_CESA_FRAGS;
/* Request queue */
typedef struct
{
MV_U8 state;
MV_U8 fragMode;
MV_U8 fixOffset;
MV_CESA_COMMAND* pCmd;
MV_CESA_COMMAND* pOrgCmd;
MV_BUF_INFO dmaDescBuf;
MV_CESA_DMA dma[MV_CESA_MAX_REQ_FRAGS];
MV_BUF_INFO cesaDescBuf;
MV_CESA_DESC* pCesaDesc;
MV_CESA_FRAGS frags;
} MV_CESA_REQ;
/* SRAM map */
/* Total SRAM size calculation */
/* SRAM size =
* MV_CESA_MAX_BUF_SIZE +
* sizeof(MV_CESA_DESC) +
* MV_CESA_MAX_IV_LENGTH +
* MV_CESA_MAX_IV_LENGTH +
* MV_CESA_MAX_DIGEST_SIZE +
* sizeof(MV_CESA_SRAM_SA)
* = 1600 + 32 + 16 + 16 + 24 + 80 + 280 (reserved) = 2048 bytes
* = 3200 + 32 + 16 + 16 + 24 + 80 + 728 (reserved) = 4096 bytes
*/
typedef struct
{
MV_U8 buf[MV_CESA_MAX_BUF_SIZE];
MV_CESA_DESC desc;
MV_U8 cryptoIV[MV_CESA_MAX_IV_LENGTH];
MV_U8 tempCryptoIV[MV_CESA_MAX_IV_LENGTH];
MV_U8 tempDigest[MV_CESA_MAX_DIGEST_SIZE+4];
MV_CESA_SRAM_SA sramSA;
} MV_CESA_SRAM_MAP;
typedef struct
{
MV_U32 openedCount;
MV_U32 closedCount;
MV_U32 fragCount;
MV_U32 reqCount;
MV_U32 maxReqCount;
MV_U32 procCount;
MV_U32 readyCount;
MV_U32 notReadyCount;
MV_U32 startCount;
#if (MV_CESA_VERSION >= 3)
MV_U32 maxChainUsage;
#endif
} MV_CESA_STATS;
/* External variables */
extern MV_CESA_STATS cesaStats;
extern MV_CESA_FRAGS cesaFrags;
extern MV_BUF_INFO cesaSramSaBuf;
extern MV_CESA_SA* pCesaSAD;
extern MV_U16 cesaMaxSA;
extern MV_CESA_REQ* pCesaReqFirst;
extern MV_CESA_REQ* pCesaReqLast;
extern MV_CESA_REQ* pCesaReqEmpty;
extern MV_CESA_REQ* pCesaReqProcess;
extern int cesaQueueDepth;
extern int cesaReqResources;
#if (MV_CESA_VERSION>= 3)
extern MV_U32 cesaChainLength;
#endif
extern MV_CESA_SRAM_MAP* cesaSramVirtPtr;
extern MV_U32 cesaSramPhysAddr;
static INLINE MV_ULONG mvCesaVirtToPhys(MV_BUF_INFO* pBufInfo, void* pVirt)
{
return (pBufInfo->bufPhysAddr + ((MV_U8*)pVirt - pBufInfo->bufVirtPtr));
}
/* Additional DEBUG functions */
void mvCesaDebugSramSA(MV_CESA_SRAM_SA* pSramSA, int mode);
void mvCesaDebugCmd(MV_CESA_COMMAND* pCmd, int mode);
void mvCesaDebugDescriptor(MV_CESA_DESC* pDesc);
#endif /* __mvCesa_h__ */

View File

@@ -0,0 +1,484 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#include "mvOs.h"
#include "mvDebug.h"
#include "cesa/mvMD5.h"
#include "cesa/mvSHA1.h"
#include "cesa/mvCesa.h"
#include "cesa/mvCesaRegs.h"
#include "cesa/AES/mvAes.h"
static const char* mvCesaDebugStateStr(MV_CESA_STATE state)
{
switch(state)
{
case MV_CESA_IDLE:
return "Idle";
case MV_CESA_PENDING:
return "Pend";
case MV_CESA_PROCESS:
return "Proc";
case MV_CESA_READY:
return "Ready";
default:
break;
}
return "Unknown";
}
static const char* mvCesaDebugOperStr(MV_CESA_OPERATION oper)
{
switch(oper)
{
case MV_CESA_MAC_ONLY:
return "MacOnly";
case MV_CESA_CRYPTO_ONLY:
return "CryptoOnly";
case MV_CESA_MAC_THEN_CRYPTO:
return "MacCrypto";
case MV_CESA_CRYPTO_THEN_MAC:
return "CryptoMac";
default:
break;
}
return "Null";
}
static const char* mvCesaDebugCryptoAlgStr(MV_CESA_CRYPTO_ALG cryptoAlg)
{
switch(cryptoAlg)
{
case MV_CESA_CRYPTO_DES:
return "DES";
case MV_CESA_CRYPTO_3DES:
return "3DES";
case MV_CESA_CRYPTO_AES:
return "AES";
default:
break;
}
return "Null";
}
static const char* mvCesaDebugMacModeStr(MV_CESA_MAC_MODE macMode)
{
switch(macMode)
{
case MV_CESA_MAC_MD5:
return "MD5";
case MV_CESA_MAC_SHA1:
return "SHA1";
case MV_CESA_MAC_HMAC_MD5:
return "HMAC-MD5";
case MV_CESA_MAC_HMAC_SHA1:
return "HMAC_SHA1";
default:
break;
}
return "Null";
}
void mvCesaDebugCmd(MV_CESA_COMMAND* pCmd, int mode)
{
mvOsPrintf("pCmd=%p, pReqPrv=%p, pSrc=%p, pDst=%p, pCB=%p, sid=%d\n",
pCmd, pCmd->pReqPrv, pCmd->pSrc, pCmd->pDst,
pCmd->pFuncCB, pCmd->sessionId);
mvOsPrintf("isUser=%d, ivOffs=%d, crOffs=%d, crLen=%d, digest=%d, macOffs=%d, macLen=%d\n",
pCmd->ivFromUser, pCmd->ivOffset, pCmd->cryptoOffset, pCmd->cryptoLength,
pCmd->digestOffset, pCmd->macOffset, pCmd->macLength);
}
/* no need to use in tool */
void mvCesaDebugMbuf(const char* str, MV_CESA_MBUF *pMbuf, int offset, int size)
{
int frag, len, fragOffset;
if(str != NULL)
mvOsPrintf("%s: pMbuf=%p, numFrags=%d, mbufSize=%d\n",
str, pMbuf, pMbuf->numFrags, pMbuf->mbufSize);
frag = mvCesaMbufOffset(pMbuf, offset, &fragOffset);
if(frag == MV_INVALID)
{
mvOsPrintf("CESA Mbuf Error: offset (%d) out of range\n", offset);
return;
}
for(; frag<pMbuf->numFrags; frag++)
{
mvOsPrintf("#%2d. bufVirt=%p, bufSize=%d\n",
frag, pMbuf->pFrags[frag].bufVirtPtr,
pMbuf->pFrags[frag].bufSize);
if(size > 0)
{
len = MV_MIN(pMbuf->pFrags[frag].bufSize, size);
mvDebugMemDump(pMbuf->pFrags[frag].bufVirtPtr+fragOffset, len, 1);
size -= len;
fragOffset = 0;
}
}
}
void mvCesaDebugRegs(void)
{
mvOsPrintf("\t CESA Registers:\n");
mvOsPrintf("MV_CESA_CMD_REG : 0x%X = 0x%08x\n",
MV_CESA_CMD_REG,
MV_REG_READ( MV_CESA_CMD_REG ) );
mvOsPrintf("MV_CESA_CHAN_DESC_OFFSET_REG : 0x%X = 0x%08x\n",
MV_CESA_CHAN_DESC_OFFSET_REG,
MV_REG_READ(MV_CESA_CHAN_DESC_OFFSET_REG) );
mvOsPrintf("MV_CESA_CFG_REG : 0x%X = 0x%08x\n",
MV_CESA_CFG_REG,
MV_REG_READ( MV_CESA_CFG_REG ) );
mvOsPrintf("MV_CESA_STATUS_REG : 0x%X = 0x%08x\n",
MV_CESA_STATUS_REG,
MV_REG_READ( MV_CESA_STATUS_REG ) );
mvOsPrintf("MV_CESA_ISR_CAUSE_REG : 0x%X = 0x%08x\n",
MV_CESA_ISR_CAUSE_REG,
MV_REG_READ( MV_CESA_ISR_CAUSE_REG ) );
mvOsPrintf("MV_CESA_ISR_MASK_REG : 0x%X = 0x%08x\n",
MV_CESA_ISR_MASK_REG,
MV_REG_READ( MV_CESA_ISR_MASK_REG ) );
#if (MV_CESA_VERSION >= 2)
mvOsPrintf("MV_CESA_TDMA_CTRL_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_CTRL_REG,
MV_REG_READ( MV_CESA_TDMA_CTRL_REG ) );
mvOsPrintf("MV_CESA_TDMA_BYTE_COUNT_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_BYTE_COUNT_REG,
MV_REG_READ( MV_CESA_TDMA_BYTE_COUNT_REG ) );
mvOsPrintf("MV_CESA_TDMA_SRC_ADDR_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_SRC_ADDR_REG,
MV_REG_READ( MV_CESA_TDMA_SRC_ADDR_REG ) );
mvOsPrintf("MV_CESA_TDMA_DST_ADDR_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_DST_ADDR_REG,
MV_REG_READ( MV_CESA_TDMA_DST_ADDR_REG ) );
mvOsPrintf("MV_CESA_TDMA_NEXT_DESC_PTR_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_NEXT_DESC_PTR_REG,
MV_REG_READ( MV_CESA_TDMA_NEXT_DESC_PTR_REG ) );
mvOsPrintf("MV_CESA_TDMA_CURR_DESC_PTR_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_CURR_DESC_PTR_REG,
MV_REG_READ( MV_CESA_TDMA_CURR_DESC_PTR_REG ) );
mvOsPrintf("MV_CESA_TDMA_ERROR_CAUSE_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_ERROR_CAUSE_REG,
MV_REG_READ( MV_CESA_TDMA_ERROR_CAUSE_REG ) );
mvOsPrintf("MV_CESA_TDMA_ERROR_MASK_REG : 0x%X = 0x%08x\n",
MV_CESA_TDMA_ERROR_MASK_REG,
MV_REG_READ( MV_CESA_TDMA_ERROR_CAUSE_REG ) );
#endif
}
void mvCesaDebugStatus(void)
{
mvOsPrintf("\n\t CESA Status\n\n");
mvOsPrintf("pReqQ=%p, qDepth=%d, reqSize=%ld bytes, qRes=%d, ",
pCesaReqFirst, cesaQueueDepth, sizeof(MV_CESA_REQ),
cesaReqResources);
#if (MV_CESA_VERSION >= 3)
mvOsPrintf("chainLength=%u\n",cesaChainLength);
#else
mvOsPrintf("\n");
#endif
mvOsPrintf("pSAD=%p, maxSA=%d, sizeSA=%ld bytes\n",
pCesaSAD, cesaMaxSA, sizeof(MV_CESA_SA));
mvOsPrintf("\n");
mvCesaDebugRegs();
mvCesaDebugStats();
mvCesaDebugStatsClear();
}
void mvCesaDebugDescriptor(MV_CESA_DESC* pDesc)
{
mvOsPrintf("config=0x%08x, crSrcOffs=0x%04x, crDstOffs=0x%04x\n",
pDesc->config, pDesc->cryptoSrcOffset, pDesc->cryptoDstOffset);
mvOsPrintf("crLen=0x%04x, crKeyOffs=0x%04x, ivOffs=0x%04x, ivBufOffs=0x%04x\n",
pDesc->cryptoDataLen, pDesc->cryptoKeyOffset,
pDesc->cryptoIvOffset, pDesc->cryptoIvBufOffset);
mvOsPrintf("macSrc=0x%04x, digest=0x%04x, macLen=0x%04x, inIv=0x%04x, outIv=0x%04x\n",
pDesc->macSrcOffset, pDesc->macDigestOffset, pDesc->macDataLen,
pDesc->macInnerIvOffset, pDesc->macOuterIvOffset);
}
void mvCesaDebugQueue(int mode)
{
mvOsPrintf("\n\t CESA Request Queue:\n\n");
mvOsPrintf("pFirstReq=%p, pLastReq=%p, qDepth=%d, reqSize=%ld bytes\n",
pCesaReqFirst, pCesaReqLast, cesaQueueDepth, sizeof(MV_CESA_REQ));
mvOsPrintf("pEmpty=%p, pProcess=%p, qResources=%d\n",
pCesaReqEmpty, pCesaReqProcess,
cesaReqResources);
if(mode != 0)
{
int count = 0;
MV_CESA_REQ* pReq = pCesaReqFirst;
for(count=0; count<cesaQueueDepth; count++)
{
/* Print out requsts */
mvOsPrintf("%02d. pReq=%p, state=%s, frag=0x%x, pCmd=%p, pDma=%p, pDesc=%p\n",
count, pReq, mvCesaDebugStateStr(pReq->state),
pReq->fragMode, pReq->pCmd, pReq->dma[0].pDmaFirst, &pReq->pCesaDesc[0]);
if(pReq->fragMode != MV_CESA_FRAG_NONE)
{
int frag;
mvOsPrintf("pFrags=%p, num=%d, next=%d, bufOffset=%d, cryptoSize=%d, macSize=%d\n",
&pReq->frags, pReq->frags.numFrag, pReq->frags.nextFrag,
pReq->frags.bufOffset, pReq->frags.cryptoSize, pReq->frags.macSize);
for(frag=0; frag<pReq->frags.numFrag; frag++)
{
mvOsPrintf("#%d: pDmaFirst=%p, pDesc=%p\n", frag,
pReq->dma[frag].pDmaFirst, &pReq->pCesaDesc[frag]);
}
}
if(mode > 1)
{
/* Print out Command */
mvCesaDebugCmd(pReq->pCmd, mode);
/* Print out Descriptor */
mvCesaDebugDescriptor(&pReq->pCesaDesc[0]);
}
pReq++;
}
}
}
void mvCesaDebugSramSA(MV_CESA_SRAM_SA* pSramSA, int mode)
{
if(pSramSA == NULL)
{
mvOsPrintf("cesaSramSA: Unexpected pSramSA=%p\n", pSramSA);
return;
}
mvOsPrintf("pSramSA=%p, sizeSramSA=%ld bytes\n",
pSramSA, sizeof(MV_CESA_SRAM_SA));
if(mode != 0)
{
mvOsPrintf("cryptoKey=%p, maxCryptoKey=%d bytes\n",
pSramSA->cryptoKey, MV_CESA_MAX_CRYPTO_KEY_LENGTH);
mvDebugMemDump(pSramSA->cryptoKey, MV_CESA_MAX_CRYPTO_KEY_LENGTH, 1);
mvOsPrintf("macInnerIV=%p, maxInnerIV=%d bytes\n",
pSramSA->macInnerIV, MV_CESA_MAX_DIGEST_SIZE);
mvDebugMemDump(pSramSA->macInnerIV, MV_CESA_MAX_DIGEST_SIZE, 1);
mvOsPrintf("macOuterIV=%p, maxOuterIV=%d bytes\n",
pSramSA->macOuterIV, MV_CESA_MAX_DIGEST_SIZE);
mvDebugMemDump(pSramSA->macOuterIV, MV_CESA_MAX_DIGEST_SIZE, 1);
}
}
void mvCesaDebugSA(short sid, int mode)
{
MV_CESA_OPERATION oper;
MV_CESA_DIRECTION dir;
MV_CESA_CRYPTO_ALG cryptoAlg;
MV_CESA_CRYPTO_MODE cryptoMode;
MV_CESA_MAC_MODE macMode;
MV_CESA_SA* pSA = &pCesaSAD[sid];
if( (pSA->valid) || ((pSA->count != 0) && (mode > 0)) || (mode >= 2) )
{
mvOsPrintf("\n\nCESA SA Entry #%d (%p) - %s (count=%d)\n",
sid, pSA,
pSA->valid ? "Valid" : "Invalid", pSA->count);
oper = (pSA->config & MV_CESA_OPERATION_MASK) >> MV_CESA_OPERATION_OFFSET;
dir = (pSA->config & MV_CESA_DIRECTION_MASK) >> MV_CESA_DIRECTION_BIT;
mvOsPrintf("%s - %s ", mvCesaDebugOperStr(oper),
(dir == MV_CESA_DIR_ENCODE) ? "Encode" : "Decode");
if(oper != MV_CESA_MAC_ONLY)
{
cryptoAlg = (pSA->config & MV_CESA_CRYPTO_ALG_MASK) >> MV_CESA_CRYPTO_ALG_OFFSET;
cryptoMode = (pSA->config & MV_CESA_CRYPTO_MODE_MASK) >> MV_CESA_CRYPTO_MODE_BIT;
mvOsPrintf("- %s - %s ", mvCesaDebugCryptoAlgStr(cryptoAlg),
(cryptoMode == MV_CESA_CRYPTO_ECB) ? "ECB" : "CBC");
}
if(oper != MV_CESA_CRYPTO_ONLY)
{
macMode = (pSA->config & MV_CESA_MAC_MODE_MASK) >> MV_CESA_MAC_MODE_OFFSET;
mvOsPrintf("- %s ", mvCesaDebugMacModeStr(macMode));
}
mvOsPrintf("\n");
if(mode > 0)
{
mvOsPrintf("config=0x%08x, cryptoKeySize=%d, digestSize=%d\n",
pCesaSAD[sid].config, pCesaSAD[sid].cryptoKeyLength,
pCesaSAD[sid].digestSize);
mvCesaDebugSramSA(pCesaSAD[sid].pSramSA, mode);
}
}
}
/**/
void mvCesaDebugSram(int mode)
{
mvOsPrintf("\n\t SRAM contents: size=%ld, pVirt=%p\n\n",
sizeof(MV_CESA_SRAM_MAP), cesaSramVirtPtr);
mvOsPrintf("\n\t Sram buffer: size=%d, pVirt=%p\n",
MV_CESA_MAX_BUF_SIZE, cesaSramVirtPtr->buf);
if(mode != 0)
mvDebugMemDump(cesaSramVirtPtr->buf, 64, 1);
mvOsPrintf("\n");
mvOsPrintf("\n\t Sram descriptor: size=%ld, pVirt=%p\n",
sizeof(MV_CESA_DESC), &cesaSramVirtPtr->desc);
if(mode != 0)
{
mvOsPrintf("\n");
mvCesaDebugDescriptor(&cesaSramVirtPtr->desc);
}
mvOsPrintf("\n\t Sram IV: size=%d, pVirt=%p\n",
MV_CESA_MAX_IV_LENGTH, &cesaSramVirtPtr->cryptoIV);
if(mode != 0)
{
mvOsPrintf("\n");
mvDebugMemDump(cesaSramVirtPtr->cryptoIV, MV_CESA_MAX_IV_LENGTH, 1);
}
mvOsPrintf("\n");
mvCesaDebugSramSA(&cesaSramVirtPtr->sramSA, 0);
}
void mvCesaDebugSAD(int mode)
{
int sid;
mvOsPrintf("\n\t Cesa SAD status: pSAD=%p, maxSA=%d\n",
pCesaSAD, cesaMaxSA);
for(sid=0; sid<cesaMaxSA; sid++)
{
mvCesaDebugSA(sid, mode);
}
}
void mvCesaDebugStats(void)
{
mvOsPrintf("\n\t Cesa Statistics\n");
mvOsPrintf("Opened=%u, Closed=%u\n",
cesaStats.openedCount, cesaStats.closedCount);
mvOsPrintf("Req=%u, maxReq=%u, frags=%u, start=%u\n",
cesaStats.reqCount, cesaStats.maxReqCount,
cesaStats.fragCount, cesaStats.startCount);
#if (MV_CESA_VERSION >= 3)
mvOsPrintf("maxChainUsage=%u\n",cesaStats.maxChainUsage);
#endif
mvOsPrintf("\n");
mvOsPrintf("proc=%u, ready=%u, notReady=%u\n",
cesaStats.procCount, cesaStats.readyCount, cesaStats.notReadyCount);
}
void mvCesaDebugStatsClear(void)
{
memset(&cesaStats, 0, sizeof(cesaStats));
}

View File

@@ -0,0 +1,357 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __mvCesaRegs_h__
#define __mvCesaRegs_h__
#include "mvTypes.h"
typedef struct
{
/* word 0 */
MV_U32 config;
/* word 1 */
MV_U16 cryptoSrcOffset;
MV_U16 cryptoDstOffset;
/* word 2 */
MV_U16 cryptoDataLen;
MV_U16 reserved1;
/* word 3 */
MV_U16 cryptoKeyOffset;
MV_U16 reserved2;
/* word 4 */
MV_U16 cryptoIvOffset;
MV_U16 cryptoIvBufOffset;
/* word 5 */
MV_U16 macSrcOffset;
MV_U16 macTotalLen;
/* word 6 */
MV_U16 macDigestOffset;
MV_U16 macDataLen;
/* word 7 */
MV_U16 macInnerIvOffset;
MV_U16 macOuterIvOffset;
} MV_CESA_DESC;
/* operation */
typedef enum
{
MV_CESA_MAC_ONLY = 0,
MV_CESA_CRYPTO_ONLY = 1,
MV_CESA_MAC_THEN_CRYPTO = 2,
MV_CESA_CRYPTO_THEN_MAC = 3,
MV_CESA_MAX_OPERATION
} MV_CESA_OPERATION;
#define MV_CESA_OPERATION_OFFSET 0
#define MV_CESA_OPERATION_MASK (0x3 << MV_CESA_OPERATION_OFFSET)
/* mac algorithm */
typedef enum
{
MV_CESA_MAC_NULL = 0,
MV_CESA_MAC_MD5 = 4,
MV_CESA_MAC_SHA1 = 5,
MV_CESA_MAC_HMAC_MD5 = 6,
MV_CESA_MAC_HMAC_SHA1 = 7,
} MV_CESA_MAC_MODE;
#define MV_CESA_MAC_MODE_OFFSET 4
#define MV_CESA_MAC_MODE_MASK (0x7 << MV_CESA_MAC_MODE_OFFSET)
typedef enum
{
MV_CESA_MAC_DIGEST_FULL = 0,
MV_CESA_MAC_DIGEST_96B = 1,
} MV_CESA_MAC_DIGEST_SIZE;
#define MV_CESA_MAC_DIGEST_SIZE_BIT 7
#define MV_CESA_MAC_DIGEST_SIZE_MASK (1 << MV_CESA_MAC_DIGEST_SIZE_BIT)
typedef enum
{
MV_CESA_CRYPTO_NULL = 0,
MV_CESA_CRYPTO_DES = 1,
MV_CESA_CRYPTO_3DES = 2,
MV_CESA_CRYPTO_AES = 3,
} MV_CESA_CRYPTO_ALG;
#define MV_CESA_CRYPTO_ALG_OFFSET 8
#define MV_CESA_CRYPTO_ALG_MASK (0x3 << MV_CESA_CRYPTO_ALG_OFFSET)
/* direction */
typedef enum
{
MV_CESA_DIR_ENCODE = 0,
MV_CESA_DIR_DECODE = 1,
} MV_CESA_DIRECTION;
#define MV_CESA_DIRECTION_BIT 12
#define MV_CESA_DIRECTION_MASK (1 << MV_CESA_DIRECTION_BIT)
/* crypto IV mode */
typedef enum
{
MV_CESA_CRYPTO_ECB = 0,
MV_CESA_CRYPTO_CBC = 1,
/* NO HW Support */
MV_CESA_CRYPTO_CTR = 10,
} MV_CESA_CRYPTO_MODE;
#define MV_CESA_CRYPTO_MODE_BIT 16
#define MV_CESA_CRYPTO_MODE_MASK (1 << MV_CESA_CRYPTO_MODE_BIT)
/* 3DES mode */
typedef enum
{
MV_CESA_CRYPTO_3DES_EEE = 0,
MV_CESA_CRYPTO_3DES_EDE = 1,
} MV_CESA_CRYPTO_3DES_MODE;
#define MV_CESA_CRYPTO_3DES_MODE_BIT 20
#define MV_CESA_CRYPTO_3DES_MODE_MASK (1 << MV_CESA_CRYPTO_3DES_MODE_BIT)
/* AES Key Length */
typedef enum
{
MV_CESA_CRYPTO_AES_KEY_128 = 0,
MV_CESA_CRYPTO_AES_KEY_192 = 1,
MV_CESA_CRYPTO_AES_KEY_256 = 2,
} MV_CESA_CRYPTO_AES_KEY_LEN;
#define MV_CESA_CRYPTO_AES_KEY_LEN_OFFSET 24
#define MV_CESA_CRYPTO_AES_KEY_LEN_MASK (0x3 << MV_CESA_CRYPTO_AES_KEY_LEN_OFFSET)
/* Fragmentation mode */
typedef enum
{
MV_CESA_FRAG_NONE = 0,
MV_CESA_FRAG_FIRST = 1,
MV_CESA_FRAG_LAST = 2,
MV_CESA_FRAG_MIDDLE = 3,
} MV_CESA_FRAG_MODE;
#define MV_CESA_FRAG_MODE_OFFSET 30
#define MV_CESA_FRAG_MODE_MASK (0x3 << MV_CESA_FRAG_MODE_OFFSET)
/*---------------------------------------------------------------------------*/
/********** Security Accelerator Command Register **************/
#define MV_CESA_CMD_REG (MV_CESA_REG_BASE + 0xE00)
#define MV_CESA_CMD_CHAN_ENABLE_BIT 0
#define MV_CESA_CMD_CHAN_ENABLE_MASK (1 << MV_CESA_CMD_CHAN_ENABLE_BIT)
#define MV_CESA_CMD_CHAN_DISABLE_BIT 2
#define MV_CESA_CMD_CHAN_DISABLE_MASK (1 << MV_CESA_CMD_CHAN_DISABLE_BIT)
/********** Security Accelerator Descriptor Pointers Register **********/
#define MV_CESA_CHAN_DESC_OFFSET_REG (MV_CESA_REG_BASE + 0xE04)
/********** Security Accelerator Configuration Register **********/
#define MV_CESA_CFG_REG (MV_CESA_REG_BASE + 0xE08)
#define MV_CESA_CFG_STOP_DIGEST_ERR_BIT 0
#define MV_CESA_CFG_STOP_DIGEST_ERR_MASK (1 << MV_CESA_CFG_STOP_DIGEST_ERR_BIT)
#define MV_CESA_CFG_WAIT_DMA_BIT 7
#define MV_CESA_CFG_WAIT_DMA_MASK (1 << MV_CESA_CFG_WAIT_DMA_BIT)
#define MV_CESA_CFG_ACT_DMA_BIT 9
#define MV_CESA_CFG_ACT_DMA_MASK (1 << MV_CESA_CFG_ACT_DMA_BIT)
#define MV_CESA_CFG_CHAIN_MODE_BIT 11
#define MV_CESA_CFG_CHAIN_MODE_MASK (1 << MV_CESA_CFG_CHAIN_MODE_BIT)
/********** Security Accelerator Status Register ***********/
#define MV_CESA_STATUS_REG (MV_CESA_REG_BASE + 0xE0C)
#define MV_CESA_STATUS_ACTIVE_BIT 0
#define MV_CESA_STATUS_ACTIVE_MASK (1 << MV_CESA_STATUS_ACTIVE_BIT)
#define MV_CESA_STATUS_DIGEST_ERR_BIT 8
#define MV_CESA_STATUS_DIGEST_ERR_MASK (1 << MV_CESA_STATUS_DIGEST_ERR_BIT)
/* Cryptographic Engines and Security Accelerator Interrupt Cause Register */
#define MV_CESA_ISR_CAUSE_REG (MV_CESA_REG_BASE + 0xE20)
/* Cryptographic Engines and Security Accelerator Interrupt Mask Register */
#define MV_CESA_ISR_MASK_REG (MV_CESA_REG_BASE + 0xE24)
#define MV_CESA_CAUSE_AUTH_MASK (1 << 0)
#define MV_CESA_CAUSE_DES_MASK (1 << 1)
#define MV_CESA_CAUSE_AES_ENCR_MASK (1 << 2)
#define MV_CESA_CAUSE_AES_DECR_MASK (1 << 3)
#define MV_CESA_CAUSE_DES_ALL_MASK (1 << 4)
#define MV_CESA_CAUSE_ACC_BIT 5
#define MV_CESA_CAUSE_ACC_MASK (1 << MV_CESA_CAUSE_ACC_BIT)
#define MV_CESA_CAUSE_ACC_DMA_BIT 7
#define MV_CESA_CAUSE_ACC_DMA_MASK (1 << MV_CESA_CAUSE_ACC_DMA_BIT)
#define MV_CESA_CAUSE_ACC_DMA_ALL_MASK (3 << MV_CESA_CAUSE_ACC_DMA_BIT)
#define MV_CESA_CAUSE_DMA_COMPL_BIT 9
#define MV_CESA_CAUSE_DMA_COMPL_MASK (1 << MV_CESA_CAUSE_DMA_COMPL_BIT)
#define MV_CESA_CAUSE_DMA_OWN_ERR_BIT 10
#define MV_CESA_CAUSE_DMA_OWN_ERR_MASK (1 < MV_CESA_CAUSE_DMA_OWN_ERR_BIT)
#define MV_CESA_CAUSE_DMA_CHAIN_PKT_BIT 11
#define MV_CESA_CAUSE_DMA_CHAIN_PKT_MASK (1 < MV_CESA_CAUSE_DMA_CHAIN_PKT_BIT)
#define MV_CESA_AUTH_DATA_IN_REG (MV_CESA_REG_BASE + 0xd38)
#define MV_CESA_AUTH_BIT_COUNT_LOW_REG (MV_CESA_REG_BASE + 0xd20)
#define MV_CESA_AUTH_BIT_COUNT_HIGH_REG (MV_CESA_REG_BASE + 0xd24)
#define MV_CESA_AUTH_INIT_VAL_DIGEST_REG(i) (MV_CESA_REG_BASE + 0xd00 + (i<<2))
#define MV_CESA_AUTH_INIT_VAL_DIGEST_A_REG (MV_CESA_REG_BASE + 0xd00)
#define MV_CESA_AUTH_INIT_VAL_DIGEST_B_REG (MV_CESA_REG_BASE + 0xd04)
#define MV_CESA_AUTH_INIT_VAL_DIGEST_C_REG (MV_CESA_REG_BASE + 0xd08)
#define MV_CESA_AUTH_INIT_VAL_DIGEST_D_REG (MV_CESA_REG_BASE + 0xd0c)
#define MV_CESA_AUTH_INIT_VAL_DIGEST_E_REG (MV_CESA_REG_BASE + 0xd10)
#define MV_CESA_AUTH_COMMAND_REG (MV_CESA_REG_BASE + 0xd18)
#define MV_CESA_AUTH_ALGORITHM_BIT 0
#define MV_CESA_AUTH_ALGORITHM_MD5 (0<<AUTH_ALGORITHM_BIT)
#define MV_CESA_AUTH_ALGORITHM_SHA1 (1<<AUTH_ALGORITHM_BIT)
#define MV_CESA_AUTH_IV_MODE_BIT 1
#define MV_CESA_AUTH_IV_MODE_INIT (0<<AUTH_IV_MODE_BIT)
#define MV_CESA_AUTH_IV_MODE_CONTINUE (1<<AUTH_IV_MODE_BIT)
#define MV_CESA_AUTH_DATA_BYTE_SWAP_BIT 2
#define MV_CESA_AUTH_DATA_BYTE_SWAP_MASK (1<<AUTH_DATA_BYTE_SWAP_BIT)
#define MV_CESA_AUTH_IV_BYTE_SWAP_BIT 4
#define MV_CESA_AUTH_IV_BYTE_SWAP_MASK (1<<AUTH_IV_BYTE_SWAP_BIT)
#define MV_CESA_AUTH_TERMINATION_BIT 31
#define MV_CESA_AUTH_TERMINATION_MASK (1<<AUTH_TERMINATION_BIT)
/*************** TDMA Control Register ************************************************/
#define MV_CESA_TDMA_CTRL_REG (MV_CESA_TDMA_REG_BASE + 0x840)
#define MV_CESA_TDMA_BURST_32B 3
#define MV_CESA_TDMA_BURST_128B 4
#define MV_CESA_TDMA_DST_BURST_OFFSET 0
#define MV_CESA_TDMA_DST_BURST_ALL_MASK (0x7<<MV_CESA_TDMA_DST_BURST_OFFSET)
#define MV_CESA_TDMA_DST_BURST_MASK(burst) ((burst)<<MV_CESA_TDMA_DST_BURST_OFFSET)
#define MV_CESA_TDMA_OUTSTAND_READ_EN_BIT 4
#define MV_CESA_TDMA_OUTSTAND_READ_EN_MASK (1<<MV_CESA_TDMA_OUTSTAND_READ_EN_BIT)
#define MV_CESA_TDMA_SRC_BURST_OFFSET 6
#define MV_CESA_TDMA_SRC_BURST_ALL_MASK (0x7<<MV_CESA_TDMA_SRC_BURST_OFFSET)
#define MV_CESA_TDMA_SRC_BURST_MASK(burst) ((burst)<<MV_CESA_TDMA_SRC_BURST_OFFSET)
#define MV_CESA_TDMA_CHAIN_MODE_BIT 9
#define MV_CESA_TDMA_NON_CHAIN_MODE_MASK (1<<MV_CESA_TDMA_CHAIN_MODE_BIT)
#define MV_CESA_TDMA_BYTE_SWAP_BIT 11
#define MV_CESA_TDMA_BYTE_SWAP_MASK (0 << MV_CESA_TDMA_BYTE_SWAP_BIT)
#define MV_CESA_TDMA_NO_BYTE_SWAP_MASK (1 << MV_CESA_TDMA_BYTE_SWAP_BIT)
#define MV_CESA_TDMA_ENABLE_BIT 12
#define MV_CESA_TDMA_ENABLE_MASK (1<<MV_CESA_TDMA_ENABLE_BIT)
#define MV_CESA_TDMA_FETCH_NEXT_DESC_BIT 13
#define MV_CESA_TDMA_FETCH_NEXT_DESC_MASK (1<<MV_CESA_TDMA_FETCH_NEXT_DESC_BIT)
#define MV_CESA_TDMA_CHAN_ACTIVE_BIT 14
#define MV_CESA_TDMA_CHAN_ACTIVE_MASK (1<<MV_CESA_TDMA_CHAN_ACTIVE_BIT)
/*------------------------------------------------------------------------------------*/
#define MV_CESA_TDMA_BYTE_COUNT_REG (MV_CESA_TDMA_REG_BASE + 0x800)
#define MV_CESA_TDMA_SRC_ADDR_REG (MV_CESA_TDMA_REG_BASE + 0x810)
#define MV_CESA_TDMA_DST_ADDR_REG (MV_CESA_TDMA_REG_BASE + 0x820)
#define MV_CESA_TDMA_NEXT_DESC_PTR_REG (MV_CESA_TDMA_REG_BASE + 0x830)
#define MV_CESA_TDMA_CURR_DESC_PTR_REG (MV_CESA_TDMA_REG_BASE + 0x870)
#define MV_CESA_TDMA_ERROR_CAUSE_REG (MV_CESA_TDMA_REG_BASE + 0x8C0)
#define MV_CESA_TDMA_ERROR_MASK_REG (MV_CESA_TDMA_REG_BASE + 0x8C4)
#endif /* __mvCesaRegs_h__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,158 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#include "mvOs.h"
#include "mvLru.h"
/* LRU Cache support */
/* Init LRU cache database */
MV_LRU_CACHE* mvLruCacheInit(int numOfEntries)
{
int i;
MV_LRU_CACHE* pLruCache;
pLruCache = mvOsMalloc(sizeof(MV_LRU_CACHE));
if(pLruCache == NULL)
{
return NULL;
}
memset(pLruCache, 0, sizeof(MV_LRU_CACHE));
pLruCache->table = mvOsMalloc(numOfEntries*sizeof(MV_LRU_ENTRY));
if(pLruCache->table == NULL)
{
mvOsFree(pLruCache);
return NULL;
}
memset(pLruCache->table, 0, numOfEntries*sizeof(MV_LRU_ENTRY));
pLruCache->tableSize = numOfEntries;
for(i=0; i<numOfEntries; i++)
{
pLruCache->table[i].next = i+1;
pLruCache->table[i].prev = i-1;
}
pLruCache->least = 0;
pLruCache->most = numOfEntries-1;
return pLruCache;
}
void mvLruCacheFinish(MV_LRU_CACHE* pLruCache)
{
mvOsFree(pLruCache->table);
mvOsFree(pLruCache);
}
/* Update LRU cache database after using cache Index */
void mvLruCacheIdxUpdate(MV_LRU_CACHE* pLruHndl, int cacheIdx)
{
int prev, next;
if(cacheIdx == pLruHndl->most)
return;
next = pLruHndl->table[cacheIdx].next;
if(cacheIdx == pLruHndl->least)
{
pLruHndl->least = next;
}
else
{
prev = pLruHndl->table[cacheIdx].prev;
pLruHndl->table[next].prev = prev;
pLruHndl->table[prev].next = next;
}
pLruHndl->table[pLruHndl->most].next = cacheIdx;
pLruHndl->table[cacheIdx].prev = pLruHndl->most;
pLruHndl->most = cacheIdx;
}
/* Delete LRU cache entry */
void mvLruCacheIdxDelete(MV_LRU_CACHE* pLruHndl, int cacheIdx)
{
int prev, next;
if(cacheIdx == pLruHndl->least)
return;
prev = pLruHndl->table[cacheIdx].prev;
if(cacheIdx == pLruHndl->most)
{
pLruHndl->most = prev;
}
else
{
next = pLruHndl->table[cacheIdx].next;
pLruHndl->table[next].prev = prev;
pLruHndl->table[prev].next = next;
}
pLruHndl->table[pLruHndl->least].prev = cacheIdx;
pLruHndl->table[cacheIdx].next = pLruHndl->least;
pLruHndl->least = cacheIdx;
}

View File

@@ -0,0 +1,112 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
/*******************************************************************************
* mvLru.h - Header File for Least Recently Used Cache algorithm
*
* DESCRIPTION:
* This header file contains macros typedefs and function declaration for
* the Least Recently Used Cache algorithm.
*
*******************************************************************************/
#ifndef __mvLru_h__
#define __mvLru_h__
typedef struct
{
int next;
int prev;
} MV_LRU_ENTRY;
typedef struct
{
int least;
int most;
MV_LRU_ENTRY* table;
int tableSize;
}MV_LRU_CACHE;
/* Find Cache index for replacement LRU */
static INLINE int mvLruCacheIdxFind(MV_LRU_CACHE* pLruHndl)
{
return pLruHndl->least;
}
/* Init LRU cache module */
MV_LRU_CACHE* mvLruCacheInit(int numOfEntries);
/* Finish LRU cache module */
void mvLruCacheFinish(MV_LRU_CACHE* pLruHndl);
/* Update LRU cache database after using cache Index */
void mvLruCacheIdxUpdate(MV_LRU_CACHE* pLruHndl, int cacheIdx);
/* Delete LRU cache entry */
void mvLruCacheIdxDelete(MV_LRU_CACHE* pLruHndl, int cacheIdx);
#endif /* __mvLru_h__ */

View File

@@ -0,0 +1,349 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#include "mvOs.h"
#include "mvMD5.h"
static void mvMD5Transform(MV_U32 buf[4], MV_U32 const in[MV_MD5_MAC_LEN]);
#ifdef MV_CPU_LE
#define mvByteReverse(buf, len) /* Nothing */
#else
static void mvByteReverse(unsigned char *buf, unsigned longs);
/*
* Note: this code is harmless on little-endian machines.
*/
static void mvByteReverse(unsigned char *buf, unsigned longs)
{
MV_U32 t;
do
{
t = (MV_U32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(MV_U32 *) buf = t;
buf += 4;
} while (--longs);
}
#endif
/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void mvMD5Init(MV_MD5_CONTEXT *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void mvMD5Update(MV_MD5_CONTEXT *ctx, unsigned char const *buf, unsigned len)
{
MV_U32 t;
/* Update bitcount */
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((MV_U32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
if (t)
{
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t)
{
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
mvByteReverse(ctx->in, MV_MD5_MAC_LEN);
mvMD5Transform(ctx->buf, (MV_U32 *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64)
{
memcpy(ctx->in, buf, 64);
mvByteReverse(ctx->in, MV_MD5_MAC_LEN);
mvMD5Transform(ctx->buf, (MV_U32 *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len);
}
/*
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void mvMD5Final(unsigned char digest[MV_MD5_MAC_LEN], MV_MD5_CONTEXT *ctx)
{
unsigned count;
unsigned char *p;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Pad out to 56 mod 64 */
if (count < 8)
{
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
mvByteReverse(ctx->in, MV_MD5_MAC_LEN);
mvMD5Transform(ctx->buf, (MV_U32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
}
else
{
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
mvByteReverse(ctx->in, 14);
/* Append length in bits and transform */
((MV_U32 *) ctx->in)[14] = ctx->bits[0];
((MV_U32 *) ctx->in)[15] = ctx->bits[1];
mvMD5Transform(ctx->buf, (MV_U32 *) ctx->in);
mvByteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, MV_MD5_MAC_LEN);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
}
/* The four core functions - F1 is optimized somewhat */
/* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
static void mvMD5Transform(MV_U32 buf[4], MV_U32 const in[MV_MD5_MAC_LEN])
{
register MV_U32 a, b, c, d;
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
void mvMD5(unsigned char const *buf, unsigned len, unsigned char* digest)
{
MV_MD5_CONTEXT ctx;
mvMD5Init(&ctx);
mvMD5Update(&ctx, buf, len);
mvMD5Final(digest, &ctx);
}
void mvHmacMd5(unsigned char const* text, int text_len,
unsigned char const* key, int key_len,
unsigned char* digest)
{
int i;
MV_MD5_CONTEXT ctx;
unsigned char k_ipad[64+1]; /* inner padding - key XORd with ipad */
unsigned char k_opad[64+1]; /* outer padding - key XORd with opad */
/* start out by storing key in pads */
memset(k_ipad, 0, 64);
memcpy(k_ipad, key, key_len);
memset(k_opad, 0, 64);
memcpy(k_opad, key, key_len);
/* XOR key with ipad and opad values */
for (i=0; i<64; i++)
{
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}
/* perform inner MD5 */
mvMD5Init(&ctx); /* init ctx for 1st pass */
mvMD5Update(&ctx, k_ipad, 64); /* start with inner pad */
mvMD5Update(&ctx, text, text_len); /* then text of datagram */
mvMD5Final(digest, &ctx); /* finish up 1st pass */
/* perform outer MD5 */
mvMD5Init(&ctx); /* init ctx for 2nd pass */
mvMD5Update(&ctx, k_opad, 64); /* start with outer pad */
mvMD5Update(&ctx, digest, 16); /* then results of 1st hash */
mvMD5Final(digest, &ctx); /* finish up 2nd pass */
}

View File

@@ -0,0 +1,93 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __mvMD5_h__
#define __mvMD5_h__
#include "mvMD5.h"
#define MV_MD5_MAC_LEN 16
typedef struct
{
MV_U32 buf[4];
MV_U32 bits[2];
MV_U8 in[64];
} MV_MD5_CONTEXT;
void mvMD5Init(MV_MD5_CONTEXT *context);
void mvMD5Update(MV_MD5_CONTEXT *context, unsigned char const *buf,
unsigned len);
void mvMD5Final(unsigned char digest[16], MV_MD5_CONTEXT *context);
void mvMD5(unsigned char const *buf, unsigned len, unsigned char* digest);
void mvHmacMd5(unsigned char const* text, int text_len,
unsigned char const* key, int key_len,
unsigned char* digest);
#endif /* __mvMD5_h__ */

View File

@@ -0,0 +1,239 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#include "mvOs.h"
#include "mvSHA1.h"
#define SHA1HANDSOFF
typedef union
{
MV_U8 c[64];
MV_U32 l[16];
} CHAR64LONG16;
static void mvSHA1Transform(MV_U32 state[5], const MV_U8 *buffer);
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
#ifdef MV_CPU_LE
#define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
(rol(block->l[i], 8) & 0x00FF00FF))
#else
#define blk0(i) block->l[i]
#endif
#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v,w,x,y,z,i) \
z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R1(v,w,x,y,z,i) \
z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R2(v,w,x,y,z,i) \
z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
#define R3(v,w,x,y,z,i) \
z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);
#define R4(v,w,x,y,z,i) \
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
w=rol(w, 30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
static void mvSHA1Transform(MV_U32 state[5], const MV_U8 *buffer)
{
MV_U32 a, b, c, d, e;
CHAR64LONG16* block;
#ifdef SHA1HANDSOFF
static MV_U32 workspace[16];
block = (CHAR64LONG16 *) workspace;
memcpy(block, buffer, 64);
#else
block = (CHAR64LONG16 *) buffer;
#endif
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
}
void mvSHA1Init(MV_SHA1_CTX* context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
}
/* Run your data through this. */
void mvSHA1Update(MV_SHA1_CTX *context, MV_U8 const *data,
unsigned int len)
{
MV_U32 i, j;
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3))
context->count[1]++;
context->count[1] += (len >> 29);
if ((j + len) > 63)
{
memcpy(&context->buffer[j], data, (i = 64-j));
mvSHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64)
{
mvSHA1Transform(context->state, &data[i]);
}
j = 0;
}
else
{
i = 0;
}
memcpy(&context->buffer[j], &data[i], len - i);
}
void mvSHA1Final(MV_U8* digest, MV_SHA1_CTX* context)
{
MV_U32 i;
MV_U8 finalcount[8];
for (i = 0; i < 8; i++)
{
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >>
((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
mvSHA1Update(context, (const unsigned char *) "\200", 1);
while ((context->count[0] & 504) != 448)
{
mvSHA1Update(context, (const unsigned char *) "\0", 1);
}
mvSHA1Update(context, finalcount, 8); /* Should cause a mvSHA1Transform()
*/
for (i = 0; i < 20; i++)
{
digest[i] = (unsigned char)
((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
/* Wipe variables */
i = 0;
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(finalcount, 0, 8);
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
mvSHA1Transform(context->state, context->buffer);
#endif
}
void mvSHA1(MV_U8 const *buf, unsigned int len, MV_U8* digest)
{
MV_SHA1_CTX ctx;
mvSHA1Init(&ctx);
mvSHA1Update(&ctx, buf, len);
mvSHA1Final(digest, &ctx);
}

View File

@@ -0,0 +1,88 @@
/*******************************************************************************
Copyright (C) Marvell International Ltd. and its affiliates
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the two
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the General
Public License Version 2, June 1991 (the "GPL License"), a copy of which is
available along with the File in the license.txt file or by writing to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. The GPL License provides additional details about this warranty
disclaimer.
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __mvSHA1_h__
#define __mvSHA1_h__
#include "mvSHA1.h"
#define MV_SHA1_MAC_LEN 20
typedef struct
{
MV_U32 state[5];
MV_U32 count[2];
MV_U8 buffer[64];
} MV_SHA1_CTX;
void mvSHA1Init(MV_SHA1_CTX *context);
void mvSHA1Update(MV_SHA1_CTX *context, MV_U8 const *buf, unsigned int len);
void mvSHA1Final(MV_U8* digest, MV_SHA1_CTX *context);
void mvSHA1(MV_U8 const *buf, unsigned int len, MV_U8* digest);
#endif /* __mvSHA1_h__ */