Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers yarrow.h Source File

yarrow.h

Go to the documentation of this file.
00001 /**
00002  * @file yarrow.h
00003  * @brief Yarrow PRNG
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneSSL Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _YARROW_H
00030 #define _YARROW_H
00031 
00032 //Dependencies
00033 #include "crypto.h"
00034 #include "aes.h"
00035 #include "sha256.h"
00036 
00037 //Common interface for PRNG algorithms
00038 #define YARROW_PRNG_ALGO (&yarrowPrngAlgo)
00039 
00040 //Pool identifiers
00041 #define YARROW_FAST_POOL_ID 0
00042 #define YARROW_SLOW_POOL_ID 1
00043 
00044 //Yarrow PRNG parameters
00045 #define YARROW_N 3
00046 #define YARROW_K 2
00047 #define YARROW_PG 10
00048 #define YARROW_FAST_THRESHOLD 100
00049 #define YARROW_SLOW_THRESHOLD 160
00050 
00051 
00052 /**
00053  * @brief Yarrow PRNG context
00054  **/
00055 
00056 typedef struct
00057 {
00058    OsMutex mutex;                    //Mutex to prevent simultaneous access to the PRNG state
00059    bool_t ready;                     //This flag tells whether the PRNG has been properly seeded
00060    uint_t currentPool[YARROW_N];     //Current pool identifier
00061    Sha256Context fastPool;           //Fast pool
00062    size_t fastPoolEntropy[YARROW_N]; //Entropy estimation (fast pool)
00063    Sha256Context slowPool;           //Slow pool
00064    size_t slowPoolEntropy[YARROW_N]; //Entropy estimation (slow pool)
00065    AesContext cipherContext;         //Cipher context
00066    uint8_t key[32];                  //Current key
00067    uint8_t counter[16];              //Counter block
00068    size_t blockCount;                //Number of blocks that have been generated
00069 } YarrowContext;
00070 
00071 
00072 //Yarrow related constants
00073 extern const PrngAlgo yarrowPrngAlgo;
00074 
00075 //Yarrow related functions
00076 error_t yarrowInit(YarrowContext *context);
00077 void yarrowRelease(YarrowContext *context);
00078 
00079 error_t yarrowSeed(YarrowContext *context, const uint8_t *input, size_t length);
00080 
00081 error_t yarrowAddEntropy(YarrowContext *context, uint_t source,
00082    const uint8_t *input, size_t length, size_t entropy);
00083 
00084 error_t yarrowRead(YarrowContext *context, uint8_t *output, size_t length);
00085 
00086 void yarrowGenerateBlock(YarrowContext *context, uint8_t *output);
00087 void yarrowFastReseed(YarrowContext *context);
00088 void yarrowSlowReseed(YarrowContext *context);
00089 
00090 #endif
00091