diff -r a179b74831c9 -r c1f20ce4abcf kerneltest/e32utils/nistsecurerng/src/matrix.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/matrix.cpp Tue Aug 31 16:34:26 2010 +0300 @@ -0,0 +1,189 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/matrix.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +R A N K A L G O R I T H M R O U T I N E S +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#define MATRIX_FORWARD_ELIMINATION 0 +#define MATRIX_BACKWARD_ELIMINATION 1 + +int +computeRank(int M, int Q, BitSequence **matrix) +{ + int i, rank, m=MIN(M,Q); + + /* FORWARD APPLICATION OF ELEMENTARY ROW OPERATIONS */ + for ( i=0; i0; i-- ) { + if ( matrix[i][i] == 1 ) + perform_elementary_row_operations(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix); + else { /* matrix[i][i] = 0 */ + if ( find_unit_element_and_swap(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix) == 1 ) + perform_elementary_row_operations(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix); + } + } + + rank = determine_rank(m, M, Q, matrix); + + return rank; +} + +void +perform_elementary_row_operations(int flag, int i, int M, int Q, BitSequence **A) +{ + int j, k; + + if ( flag == MATRIX_FORWARD_ELIMINATION ) { + for ( j=i+1; j=0; j-- ) + if ( A[j][i] == 1 ) + for ( k=0; k= 0) && (A[index][i] == 0) ) + index--; + if ( index >= 0 ) + row_op = swap_rows(i, index, Q, A); + } + + return row_op; +} + +int +swap_rows(int i, int index, int Q, BitSequence **A) +{ + int p; + BitSequence temp; + + for ( p=0; p