seed_ofb.c revision 183234
1190558Simp/* crypto/seed/seed_ofb.c -*- mode:C; c-file-style: "eay" -*- */ 2190558Simp/* ==================================================================== 3190558Simp * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. 4190558Simp * 5190558Simp * Redistribution and use in source and binary forms, with or without 6190558Simp * modification, are permitted provided that the following conditions 7190558Simp * are met: 8190558Simp * 9190558Simp * 1. Redistributions of source code must retain the above copyright 10190558Simp * notice, this list of conditions and the following disclaimer. 11190558Simp * 12190558Simp * 2. Redistributions in binary form must reproduce the above copyright 13190558Simp * notice, this list of conditions and the following disclaimer in 14190558Simp * the documentation and/or other materials provided with the 15190558Simp * distribution. 16190558Simp * 17190558Simp * 3. All advertising materials mentioning features or use of this 18190558Simp * software must display the following acknowledgment: 19190558Simp * "This product includes software developed by the OpenSSL Project 20190558Simp * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21190558Simp * 22190558Simp * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23190558Simp * endorse or promote products derived from this software without 24190558Simp * prior written permission. For written permission, please contact 25190558Simp * openssl-core@openssl.org. 26190558Simp * 27190558Simp * 5. Products derived from this software may not be called "OpenSSL" 28190558Simp * nor may "OpenSSL" appear in their names without prior written 29190558Simp * permission of the OpenSSL Project. 30190558Simp * 31190558Simp * 6. Redistributions of any form whatsoever must retain the following 32190558Simp * acknowledgment: 33190558Simp * "This product includes software developed by the OpenSSL Project 34190558Simp * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35190558Simp * 36190558Simp * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37190558Simp * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38190558Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39190558Simp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40190558Simp * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41190558Simp * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42190558Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43190558Simp * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44190558Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45190558Simp * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46190558Simp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47190558Simp * OF THE POSSIBILITY OF SUCH DAMAGE. 48190558Simp * ==================================================================== 49190558Simp * 50190558Simp */ 51190558Simp/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 52190558Simp * All rights reserved. 53190558Simp * 54190558Simp * This package is an SSL implementation written 55190558Simp * by Eric Young (eay@cryptsoft.com). 56190558Simp * The implementation was written so as to conform with Netscapes SSL. 57190558Simp * 58190558Simp * This library is free for commercial and non-commercial use as long as 59190558Simp * the following conditions are aheared to. The following conditions 60190558Simp * apply to all code found in this distribution, be it the RC4, RSA, 61190558Simp * lhash, DES, etc., code; not just the SSL code. The SSL documentation 62190558Simp * included with this distribution is covered by the same copyright terms 63190558Simp * except that the holder is Tim Hudson (tjh@cryptsoft.com). 64190558Simp * 65190558Simp * Copyright remains Eric Young's, and as such any Copyright notices in 66190558Simp * the code are not to be removed. 67190558Simp * If this package is used in a product, Eric Young should be given attribution 68190558Simp * as the author of the parts of the library used. 69190558Simp * This can be in the form of a textual message at program startup or 70190558Simp * in documentation (online or textual) provided with the package. 71190558Simp * 72190558Simp * Redistribution and use in source and binary forms, with or without 73190558Simp * modification, are permitted provided that the following conditions 74190558Simp * are met: 75190558Simp * 1. Redistributions of source code must retain the copyright 76190558Simp * notice, this list of conditions and the following disclaimer. 77190558Simp * 2. Redistributions in binary form must reproduce the above copyright 78190558Simp * notice, this list of conditions and the following disclaimer in the 79190558Simp * documentation and/or other materials provided with the distribution. 80190558Simp * 3. All advertising materials mentioning features or use of this software 81190558Simp * must display the following acknowledgement: 82190558Simp * "This product includes cryptographic software written by 83190558Simp * Eric Young (eay@cryptsoft.com)" 84190558Simp * The word 'cryptographic' can be left out if the rouines from the library 85190558Simp * being used are not cryptographic related :-). 86190558Simp * 4. If you include any Windows specific code (or a derivative thereof) from 87190558Simp * the apps directory (application code) you must include an acknowledgement: 88190558Simp * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 89190558Simp * 90190558Simp * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 91190558Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 92190558Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 93190558Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 94190558Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 95190558Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 96190558Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 97190558Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 98190558Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 99213229Smarius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 100190558Simp * SUCH DAMAGE. 101190558Simp * 102213364Smarius * The licence and distribution terms for any publically available version or 103190558Simp * derivative of this code cannot be changed. i.e. this code cannot simply be 104190558Simp * copied and put under another distribution licence 105190558Simp * [including the GNU Public Licence.] 106213364Smarius */ 107190558Simp 108190558Simp#include "seed_locl.h" 109190558Simp#include <string.h> 110190558Simp 111190558Simpvoid SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, 112190558Simp size_t len, const SEED_KEY_SCHEDULE *ks, 113190558Simp unsigned char ivec[SEED_BLOCK_SIZE], int *num) 114190558Simp { 115190558Simp int n; 116190558Simp 117190558Simp n = *num; 118190558Simp 119190558Simp while (len--) 120190558Simp { 121190558Simp if (n == 0) 122190558Simp SEED_encrypt(ivec, ivec, ks); 123190558Simp *(out++) = *(in++) ^ ivec[n]; 124190558Simp n = (n+1) % SEED_BLOCK_SIZE; 125190558Simp } 126190558Simp 127190558Simp *num = n; 128190558Simp } 129190558Simp