Skip to content
Snippets Groups Projects
Select Git revision
  • 0420f9b96d2b77004bc81b5094a0b314cd684aed
  • master default protected
  • streebog
  • gost28147
  • master-updates
  • ed448
  • shake256
  • curve448
  • ecc-sqrt
  • gosthash94cp
  • cmac64
  • block16-refactor
  • siv-mode
  • cmac-layout
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
  • nettle_3.5rc1
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
41 results

cbc.h

  • Forked from Nettle / nettle
    Source project has a limited visibility.
    twofish.c 15.87 KiB
    /* twofish.c
     *
     * The twofish block cipher.
     */
    
    /* twofish - An implementation of the twofish cipher.
     * Copyright (C) 1999 Ruud de Rooij <ruud@debian.org>
     *
     * Modifications for lsh, integrated testing
     * Copyright (C) 1999 J.H.M. Dassen (Ray) <jdassen@wi.LeidenUniv.nl>
     *
     * Integrated with the nettle library,
     * Copyright (C) 2001 Niels Mller
     */
    
    /* nettle, low-level cryptographics library
     *
     * The nettle library is free software; you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published by
     * the Free Software Foundation; either version 2.1 of the License, or (at your
     * option) any later version.
     * 
     * The nettle Library is distributed in the hope that it will be useful, but
     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     * License for more details.
     * 
     * You should have received a copy of the GNU Lesser General Public License
     * along with the nettle library; see the file COPYING.LIB.  If not, write to
     * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
     * MA 02111-1307, USA.
     */
    
    #include "twofish.h"
    
    #include "macros.h"
    
    #include <assert.h>
    #include <string.h>
    
    /* Bitwise rotations on 32-bit words.  These are defined as macros that
     * evaluate their argument twice, so do not apply to any expressions with
     * side effects.
     */
    
    #define rol1(x) (((x) << 1) | (((x) & 0x80000000) >> 31))
    #define rol8(x) (((x) << 8) | (((x) & 0xFF000000) >> 24))
    #define rol9(x) (((x) << 9) | (((x) & 0xFF800000) >> 23))
    #define ror1(x) (((x) >> 1) | (((x) & 0x00000001) << 31))
    
    /* ------------------------------------------------------------------------- */
    
    /* The permutations q0 and q1.  These are fixed permutations on 8-bit values.
     * The permutations have been computed using the program generate_q
     * which is distributed along with this file.
     */
    
    static const uint8_t q0[] = { 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
                         0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
                         0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
                         0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48,
                         0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23,
                         0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
                         0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C,
                         0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61,
                         0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
                         0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1,
                         0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66,
                         0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
                         0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA,