Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of http://git.ipxe.org/ipxe
  • Loading branch information
Jarrod Johnson committed Jan 15, 2012
2 parents 03281fe + 18d2887 commit eb4d571
Show file tree
Hide file tree
Showing 8 changed files with 1,386 additions and 9 deletions.
669 changes: 669 additions & 0 deletions src/drivers/net/vmxnet3.c

Large diffs are not rendered by default.

497 changes: 497 additions & 0 deletions src/drivers/net/vmxnet3.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/include/ipxe/errfile.h
Expand Up @@ -139,6 +139,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ERRFILE_igbvf_main ( ERRFILE_DRIVER | 0x005e0000 )
#define ERRFILE_ath9k ( ERRFILE_DRIVER | 0x005f0000 )
#define ERRFILE_ath ( ERRFILE_DRIVER | 0x00600000 )
#define ERRFILE_vmxnet3 ( ERRFILE_DRIVER | 0x00610000 )

#define ERRFILE_scsi ( ERRFILE_DRIVER | 0x00700000 )
#define ERRFILE_arbel ( ERRFILE_DRIVER | 0x00710000 )
Expand Down
24 changes: 15 additions & 9 deletions src/net/udp/dns.c
Expand Up @@ -222,18 +222,24 @@ static char * dns_qualify_name ( const char *string ) {
* DNS names consist of "<length>element" pairs.
*/
static char * dns_make_name ( const char *string, char *buf ) {
char *length_byte = buf++;
char *length_byte;
char c;

while ( ( c = *(string++) ) ) {
if ( c == '.' ) {
*length_byte = buf - length_byte - 1;
length_byte = buf;
length_byte = buf++;
*length_byte = 0;
do {
c = *(string++);
if ( ( c == '.' ) || ( c == '\0' ) ) {
if ( *length_byte ) {
length_byte = buf++;
*length_byte = 0;
}
} else {
*(buf++) = c;
(*length_byte)++;
}
*(buf++) = c;
}
*length_byte = buf - length_byte - 1;
*(buf++) = '\0';
} while ( c );

return buf;
}

Expand Down
69 changes: 69 additions & 0 deletions src/tests/digest_test.c
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** @file
*
* Digest self-tests
*
*/

#include <string.h>
#include <ipxe/crypto.h>
#include "digest_test.h"

/**
* Test digest algorithm
*
* @v digest Digest algorithm
* @v fragments Digest test fragment list, or NULL
* @v data Test data
* @v len Length of test data
* @v expected Expected digest value
* @ret ok Digest value is as expected
*/
int digest_test ( struct digest_algorithm *digest,
struct digest_test_fragments *fragments,
void *data, size_t len, void *expected ) {
uint8_t ctx[digest->ctxsize];
uint8_t out[digest->digestsize];
size_t frag_len = 0;
unsigned int i;

/* Initialise digest */
digest_init ( digest, ctx );

/* Update digest fragment-by-fragment */
for ( i = 0 ; len && ( i < ( sizeof ( fragments->len ) /
sizeof ( fragments->len[0] ) ) ) ; i++ ) {
if ( fragments )
frag_len = fragments->len[i];
if ( ( frag_len == 0 ) || ( frag_len < len ) )
frag_len = len;
digest_update ( digest, ctx, data, frag_len );
data += frag_len;
len -= frag_len;
}

/* Finalise digest */
digest_final ( digest, ctx, out );

/* Compare against expected output */
return ( memcmp ( expected, out, sizeof ( out ) ) == 0 );
}
36 changes: 36 additions & 0 deletions src/tests/digest_test.h
@@ -0,0 +1,36 @@
#ifndef _DIGEST_TEST_H
#define _DIGEST_TEST_H

FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>
#include <ipxe/crypto.h>
#include <ipxe/test.h>

/** Maximum number of digest test fragments */
#define NUM_DIGEST_TEST_FRAG 8

/** A digest test fragment list */
struct digest_test_fragments {
/** Fragment lengths */
size_t len[NUM_DIGEST_TEST_FRAG];
};

extern int digest_test ( struct digest_algorithm *digest,
struct digest_test_fragments *fragments,
void *data, size_t len, void *expected );

/**
* Report digest test result
*
* @v digest Digest algorithm
* @v fragments Digest test fragment list, or NULL
* @v data Test data
* @v len Length of test data
* @v expected Expected digest value
*/
#define digest_ok( digest, fragments, data, len, expected ) do { \
ok ( digest_test ( digest, fragments, data, len, expected ) ); \
} while ( 0 )

#endif /* _DIGEST_TEST_H */
98 changes: 98 additions & 0 deletions src/tests/sha1_test.c
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** @file
*
* SHA-1 tests
*
*/

#include <stdint.h>
#include <ipxe/sha1.h>
#include <ipxe/test.h>
#include "digest_test.h"

/** An SHA-1 test vector */
struct sha1_test_vector {
/** Test data */
void *data;
/** Test data length */
size_t len;
/** Expected digest */
uint8_t digest[SHA1_DIGEST_SIZE];
};

/** SHA-1 test vectors */
static struct sha1_test_vector sha1_test_vectors[] = {
/* Empty test data
*
* Expected digest value obtained from "sha1sum /dev/null"
*/
{ NULL, 0,
{ 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55,
0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 } },
/* Test data and expected digests taken from the NIST
* Cryptographic Toolkit Algorithm Examples at
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA1.pdf
*/
{ "abc", 3,
{ 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e,
0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d } },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
{ 0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae,
0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1 } },
};

/** SHA-1 test fragment lists */
static struct digest_test_fragments sha1_test_fragments[] = {
{ { 0, -1UL, } },
{ { 1, 1, 1, 1, 1, 1, 1, 1 } },
{ { 2, 0, 23, 4, 6, 1, 0 } },
};

/**
* Perform SHA-1 self-test
*
*/
static void sha1_test_exec ( void ) {
struct digest_algorithm *digest = &sha1_algorithm;
struct sha1_test_vector *test;
unsigned int i;
unsigned int j;

for ( i = 0 ; i < ( sizeof ( sha1_test_vectors ) /
sizeof ( sha1_test_vectors[0] ) ) ; i++ ) {
test = &sha1_test_vectors[i];
/* Test with a single pass */
digest_ok ( digest, NULL, test->data, test->len, test->digest );
/* Test with fragment lists */
for ( j = 0 ; j < ( sizeof ( sha1_test_fragments ) /
sizeof ( sha1_test_fragments[0] ) ) ; j++ ){
digest_ok ( digest, &sha1_test_fragments[j],
test->data, test->len, test->digest );
}
}
}

/** SHA-1 self-test */
struct self_test sha1_test __self_test = {
.name = "sha1",
.exec = sha1_test_exec,
};
1 change: 1 addition & 0 deletions src/tests/test.c
Expand Up @@ -140,3 +140,4 @@ struct init_fn test_init_fn __init_fn ( INIT_NORMAL ) = {

/* Drag in all applicable self-tests */
REQUIRE_OBJECT ( list_test );
REQUIRE_OBJECT ( sha1_test );

0 comments on commit eb4d571

Please sign in to comment.