mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 13:42:14 +00:00
Oops
This commit is contained in:
339
COPYING
Normal file
339
COPYING
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
(at your option) 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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
2
Makefile.am
Normal file
2
Makefile.am
Normal file
@@ -0,0 +1,2 @@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
SUBDIRS = src man
|
||||
2
README
2
README
@@ -22,7 +22,7 @@ RELEASE NOTES
|
||||
v0.22
|
||||
- Use const *banner instead of nwipe_options.banner(Cleanup of code)
|
||||
- Update manpage
|
||||
- Disable the "Kill the GUI thread" since it segfaults
|
||||
- Disable "Kill the GUI thread"
|
||||
|
||||
v0.21
|
||||
- Fix ETA not updating properly and bad total throughput display. Thanks (Niels Bassler).
|
||||
|
||||
15
README.md
Normal file
15
README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
nwipe is a command that will securely erase disks using a variety of
|
||||
recognised methods. It is a fork of the dwipe command used by
|
||||
Darik's Boot and Nuke (dban). nwipe is included with partedmagic if you
|
||||
want a quick and easy bootable CD version. nwipe was created out of
|
||||
a need to run the DBAN dwipe command outside of DBAN, in order to
|
||||
allow its use with any host distribution, thus giving better hardware
|
||||
support.
|
||||
|
||||
To use from the git repository, first create all the autoconf files with
|
||||
./init.sh
|
||||
|
||||
Then do the standard ./configure --prefix=/usr && make && make install
|
||||
|
||||
For release notes please see the [README file](README)
|
||||
|
||||
8
init.sh
Executable file
8
init.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to create all the required autoconf files
|
||||
|
||||
aclocal
|
||||
autoheader
|
||||
automake --add-missing
|
||||
autoconf
|
||||
1
man/Makefile.am
Normal file
1
man/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
dist_man_MANS = nwipe.1
|
||||
11
src/Makefile.am
Normal file
11
src/Makefile.am
Normal file
@@ -0,0 +1,11 @@
|
||||
# what flags you want to pass to the C compiler & linker
|
||||
#CFLAGS = -lncurses -lparted
|
||||
AM_CFLAGS =
|
||||
AM_LDFLAGS =
|
||||
|
||||
# this lists the binaries to produce, the (non-PHONY, binary) targets in
|
||||
# the previous manual Makefile
|
||||
bin_PROGRAMS = nwipe
|
||||
nwipe_SOURCES = context.h isaac_rand.c logging.h options.h prng.h nwipe.c gui.c isaac_rand.h method.h pass.c device.c gui.h isaac_standard.h mt19937ar-cok.c nwipe.h mt19937ar-cok.h pass.h device.h logging.c method.c options.c prng.c version.c version.h
|
||||
nwipe_CFLAGS = $(PARTED_CFLAGS)
|
||||
nwipe_LDADD = $(PARTED_LIBS)
|
||||
144
src/context.h
Normal file
144
src/context.h
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* context.h: The internal state representation of nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CONTEXT_H_
|
||||
#define CONTEXT_H_
|
||||
|
||||
#include "prng.h"
|
||||
|
||||
typedef enum nwipe_device_t_
|
||||
{
|
||||
NWIPE_DEVICE_UNKNOWN = 0, /* Unknown device. */
|
||||
NWIPE_DEVICE_IDE,
|
||||
NWIPE_DEVICE_SCSI,
|
||||
NWIPE_DEVICE_COMPAQ, /* Unimplemented. */
|
||||
NWIPE_DEVICE_USB, /* Unimplemented. */
|
||||
NWIPE_DEVICE_IEEE1394 /* Unimplemented. */
|
||||
} nwipe_device_t;
|
||||
|
||||
typedef enum nwipe_pass_t_
|
||||
{
|
||||
NWIPE_PASS_NONE = 0, /* Not running. */
|
||||
NWIPE_PASS_WRITE, /* Writing patterns to the device. */
|
||||
NWIPE_PASS_VERIFY, /* Verifying a pass. */
|
||||
NWIPE_PASS_FINAL_BLANK, /* Filling the device with zeros. */
|
||||
NWIPE_PASS_FINAL_OPS2 /* Special case for nwipe_ops2. */
|
||||
} nwipe_pass_t;
|
||||
|
||||
typedef enum nwipe_select_t_
|
||||
{
|
||||
NWIPE_SELECT_NONE = 0, /* Unused. */
|
||||
NWIPE_SELECT_TRUE, /* Wipe this device. */
|
||||
NWIPE_SELECT_TRUE_PARENT, /* A parent of this device has been selected, so the wipe is implied. */
|
||||
NWIPE_SELECT_FALSE, /* Do not wipe this device. */
|
||||
NWIPE_SELECT_FALSE_CHILD, /* A child of this device has been selected, so we can't wipe this device. */
|
||||
NWIPE_SELECT_DISABLED /* Do not wipe this device and do not allow it to be selected. */
|
||||
} nwipe_select_t;
|
||||
|
||||
|
||||
#define NWIPE_KNOB_SPEEDRING_SIZE 30
|
||||
#define NWIPE_KNOB_SPEEDRING_GRANULARITY 10
|
||||
|
||||
typedef struct nwipe_speedring_t_
|
||||
{
|
||||
u64 bytes[NWIPE_KNOB_SPEEDRING_SIZE];
|
||||
u64 bytestotal;
|
||||
u64 byteslast;
|
||||
time_t times[NWIPE_KNOB_SPEEDRING_SIZE];
|
||||
time_t timestotal;
|
||||
time_t timeslast;
|
||||
u32 position;
|
||||
} nwipe_speedring_t;
|
||||
|
||||
|
||||
typedef struct nwipe_context_t_
|
||||
{
|
||||
int block_size; /* The soft block size reported the device. */
|
||||
int device_bus; /* The device bus number. */
|
||||
int device_fd; /* The file descriptor of the device file being wiped. */
|
||||
int device_host; /* The host number. */
|
||||
struct hd_driveid device_id; /* The WIN_IDENTIFY data for IDE drives. */
|
||||
int device_lun; /* The device logical unit number. */
|
||||
int device_major; /* The major device number. */
|
||||
int device_minor; /* The minor device number. */
|
||||
int device_part; /* The device partition or slice number. */
|
||||
char* device_name; /* The device file name. */
|
||||
off64_t device_size; /* The device size in bytes. */
|
||||
struct stat device_stat; /* The device file state from fstat(). */
|
||||
nwipe_device_t device_type; /* Indicates an IDE, SCSI, or Compaq SMART device. */
|
||||
int device_target; /* The device target. */
|
||||
u64 eta; /* The estimated number of seconds until method completion. */
|
||||
int entropy_fd; /* The entropy source. Usually /dev/urandom. */
|
||||
char* label; /* The string that we will show the user. */
|
||||
int pass_count; /* The number of passes performed by the working wipe method. */
|
||||
u64 pass_done; /* The number of bytes that have already been i/o'd in this pass. */
|
||||
u64 pass_errors; /* The number of errors across all passes. */
|
||||
u64 pass_size; /* The total number of i/o bytes across all passes. */
|
||||
nwipe_pass_t pass_type; /* The type of the current working pass. */
|
||||
int pass_working; /* The current working pass. */
|
||||
nwipe_prng_t* prng; /* The PRNG implementation. */
|
||||
nwipe_entropy_t prng_seed; /* The random data that is used to seed the PRNG. */
|
||||
void* prng_state; /* The private internal state of the PRNG. */
|
||||
int result; /* The process return value. */
|
||||
int round_count; /* The number of rounds performed by the working wipe method. */
|
||||
u64 round_done; /* The number of bytes that have already been i/o'd. */
|
||||
u64 round_errors; /* The number of errors across all rounds. */
|
||||
u64 round_size; /* The total number of i/o bytes across all rounds. */
|
||||
double round_percent; /* The percentage complete across all rounds. */
|
||||
int round_working; /* The current working round. */
|
||||
int sector_size; /* The hard sector size reported by the device. */
|
||||
nwipe_select_t select; /* Indicates whether this device should be wiped. */
|
||||
int signal; /* Set when the child is killed by a signal. */
|
||||
nwipe_speedring_t speedring; /* Ring buffer for computing the rolling throughput average. */
|
||||
short sync_status; /* A flag to indicate when the method is syncing. */
|
||||
pthread_t thread; /* The ID of the thread. */
|
||||
u64 throughput; /* Average throughput in bytes per second. */
|
||||
u64 verify_errors; /* The number of verification errors across all passes. */
|
||||
struct hd_driveid identity; /* The serial number of the drive (where applicable) */
|
||||
} nwipe_context_t;
|
||||
|
||||
|
||||
/* We use 2 data structs to pass data between threads. */
|
||||
|
||||
/* The first contains any required values: */
|
||||
/* Values cannot form part of the second array below, hence the need for this. */
|
||||
typedef struct
|
||||
{
|
||||
int nwipe_enumerated; /* The number of devices available. */
|
||||
int nwipe_selected; /* The number of devices being wiped. */
|
||||
time_t maxeta; /* The estimated runtime of the slowest device. */
|
||||
u64 throughput; /* Total throughput */
|
||||
u64 errors; /* The combined number of errors of all processes. */
|
||||
pthread_t *gui_thread; /* The ID of GUI thread. */
|
||||
} nwipe_misc_thread_data_t;
|
||||
|
||||
/* The second points to the first structure, as well as the structure of all the devices */
|
||||
typedef struct
|
||||
{
|
||||
nwipe_context_t **c; /* Pointer to the nwipe context structure. */
|
||||
nwipe_misc_thread_data_t *nwipe_misc_thread_data; /* Pointer to the misc structure above. */
|
||||
} nwipe_thread_data_ptr_t;
|
||||
|
||||
|
||||
#endif /* CONTEXT_H_ */
|
||||
|
||||
/* eof */
|
||||
33
src/device.h
Normal file
33
src/device.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* device.h: Device routines for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DEVICE_H_
|
||||
#define DEVICE_H_
|
||||
|
||||
void nwipe_device_identify( nwipe_context_t* c ); /* Get hardware information about the device. */
|
||||
int nwipe_device_scan( nwipe_context_t*** c ); /* Find devices that we can wipe. */
|
||||
int nwipe_device_get( nwipe_context_t*** c, char **devnamelist, int ndevnames ); /* Get info about devices to wipe */
|
||||
|
||||
#endif /* DEVICE_H_ */
|
||||
|
||||
/* eof */
|
||||
44
src/gui.h
Normal file
44
src/gui.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* gui.h: An ncurses GUI for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_H_
|
||||
#define GUI_H_
|
||||
|
||||
void nwipe_gui_free( void ); /* Stop the GUI. */
|
||||
void nwipe_gui_init( void ); /* Start the GUI. */
|
||||
void nwipe_gui_select( int count, nwipe_context_t** c ); /* Select devices to wipe. */
|
||||
void *nwipe_gui_status( void *ptr ); /* Update operation progress. */
|
||||
void nwipe_gui_method( void ); /* Change the method option. */
|
||||
void nwipe_gui_options( void ); /* Update the options window. */
|
||||
void nwipe_gui_prng( void ); /* Change the prng option. */
|
||||
void nwipe_gui_rounds( void ); /* Change the rounds option. */
|
||||
void nwipe_gui_verify( void ); /* Change the verify option. */
|
||||
void nwipe_gui_noblank( void ); /* Change the noblank option. */
|
||||
|
||||
int compute_stats(void *ptr);
|
||||
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_done, time_t speedring_now );
|
||||
|
||||
|
||||
#endif /* GUI_H_ */
|
||||
|
||||
/* eof */
|
||||
56
src/isaac_rand.h
Normal file
56
src/isaac_rand.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
rand.h: definitions for a random number generator
|
||||
By Bob Jenkins, 1996, Public Domain
|
||||
MODIFIED:
|
||||
960327: Creation (addition of randinit, really)
|
||||
970719: use context, not global variables, for internal state
|
||||
980324: renamed seed to flag
|
||||
980605: recommend RANDSIZL=4 for noncryptography.
|
||||
010626: note this is public domain
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef STANDARD
|
||||
#include "isaac_standard.h"
|
||||
#endif
|
||||
|
||||
#ifndef RAND
|
||||
#define RAND
|
||||
#define RANDSIZL (8) /* I recommend 8 for crypto, 4 for simulations */
|
||||
#define RANDSIZ (1<<RANDSIZL)
|
||||
|
||||
/* context of random number generator */
|
||||
struct randctx
|
||||
{
|
||||
ub4 randcnt;
|
||||
ub4 randrsl[RANDSIZ];
|
||||
ub4 randmem[RANDSIZ];
|
||||
ub4 randa;
|
||||
ub4 randb;
|
||||
ub4 randc;
|
||||
};
|
||||
typedef struct randctx randctx;
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
If (flag==TRUE), then use the contents of randrsl[0..RANDSIZ-1] as the seed.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
void randinit(/*_ randctx *r, word flag _*/);
|
||||
|
||||
void isaac(/*_ randctx *r _*/);
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
Call rand(/o_ randctx *r _o/) to retrieve a single 32-bit random value
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
#define isaac_rand(r) \
|
||||
(!(r)->randcnt-- ? \
|
||||
(isaac(r), (r)->randcnt=RANDSIZ-1, (r)->randrsl[(r)->randcnt]) : \
|
||||
(r)->randrsl[(r)->randcnt])
|
||||
|
||||
#endif /* RAND */
|
||||
|
||||
|
||||
57
src/isaac_standard.h
Normal file
57
src/isaac_standard.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
Standard definitions and types, Bob Jenkins
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef STANDARD
|
||||
# define STANDARD
|
||||
# ifndef STDIO
|
||||
# include <stdio.h>
|
||||
# define STDIO
|
||||
# endif
|
||||
# ifndef STDDEF
|
||||
# include <stddef.h>
|
||||
# define STDDEF
|
||||
# endif
|
||||
typedef unsigned long long ub8;
|
||||
#define UB8MAXVAL 0xffffffffffffffffLL
|
||||
#define UB8BITS 64
|
||||
typedef signed long long sb8;
|
||||
#define SB8MAXVAL 0x7fffffffffffffffLL
|
||||
typedef unsigned long int ub4; /* unsigned 4-byte quantities */
|
||||
#define UB4MAXVAL 0xffffffff
|
||||
typedef signed long int sb4;
|
||||
#define UB4BITS 32
|
||||
#define SB4MAXVAL 0x7fffffff
|
||||
typedef unsigned short int ub2;
|
||||
#define UB2MAXVAL 0xffff
|
||||
#define UB2BITS 16
|
||||
typedef signed short int sb2;
|
||||
#define SB2MAXVAL 0x7fff
|
||||
typedef unsigned char ub1;
|
||||
#define UB1MAXVAL 0xff
|
||||
#define UB1BITS 8
|
||||
typedef signed char sb1; /* signed 1-byte quantities */
|
||||
#define SB1MAXVAL 0x7f
|
||||
typedef int word; /* fastest type available */
|
||||
|
||||
#define bis(target,mask) ((target) |= (mask))
|
||||
#define bic(target,mask) ((target) &= ~(mask))
|
||||
#define bit(target,mask) ((target) & (mask))
|
||||
#ifndef min
|
||||
# define min(a,b) (((a)<(b)) ? (a) : (b))
|
||||
#endif /* min */
|
||||
#ifndef max
|
||||
# define max(a,b) (((a)<(b)) ? (b) : (a))
|
||||
#endif /* max */
|
||||
#ifndef align
|
||||
# define align(a) (((ub4)a+(sizeof(void *)-1))&(~(sizeof(void *)-1)))
|
||||
#endif /* align */
|
||||
#ifndef abs
|
||||
# define abs(a) (((a)>0) ? (a) : -(a))
|
||||
#endif
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define SUCCESS 0 /* 1 on VAX */
|
||||
|
||||
#endif /* STANDARD */
|
||||
222
src/logging.c
Normal file
222
src/logging.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* logging.c: Logging facilities for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "context.h"
|
||||
#include "method.h"
|
||||
#include "prng.h"
|
||||
#include "options.h"
|
||||
#include "logging.h"
|
||||
|
||||
int const MAX_LOG_LINE_CHARS = 512;
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
char **log_lines;
|
||||
int log_current_element = 0;
|
||||
int log_elements_allocated = 0;
|
||||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void nwipe_log( nwipe_log_t level, const char* format, ... )
|
||||
{
|
||||
/**
|
||||
* Writes a message to the program log file.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* A time buffer. */
|
||||
time_t t;
|
||||
|
||||
/* A pointer to the system time struct. */
|
||||
struct tm* p;
|
||||
|
||||
/* Get the current time. */
|
||||
t = time( NULL );
|
||||
p = gmtime( &t );
|
||||
|
||||
pthread_mutex_lock( &mutex1 );
|
||||
|
||||
/* Increase the current log element pointer - we will write here */
|
||||
if (log_current_element == log_elements_allocated) {
|
||||
log_elements_allocated++;
|
||||
log_lines = (char **) realloc (log_lines, (log_elements_allocated) * sizeof(char *));
|
||||
log_lines[log_current_element] = malloc(MAX_LOG_LINE_CHARS * sizeof(char));
|
||||
}
|
||||
|
||||
/* Position of writing to current log string */
|
||||
int line_current_pos = 0;
|
||||
|
||||
/* Print the date. The rc script uses the same format. */
|
||||
line_current_pos = snprintf( log_lines[log_current_element], MAX_LOG_LINE_CHARS, "[%i/%02i/%02i %02i:%02i:%02i] nwipe: ", \
|
||||
1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec );
|
||||
|
||||
switch( level )
|
||||
{
|
||||
|
||||
case NWIPE_LOG_NONE:
|
||||
/* Do nothing. */
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_DEBUG:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "debug: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_INFO:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "info: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_NOTICE:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "notice: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_WARNING:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "warning: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_ERROR:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "error: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_FATAL:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "fatal: " );
|
||||
break;
|
||||
|
||||
case NWIPE_LOG_SANITY:
|
||||
/* TODO: Request that the user report the log. */
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "sanity: " );
|
||||
break;
|
||||
|
||||
default:
|
||||
line_current_pos += snprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, "level %i: ", level );
|
||||
|
||||
}
|
||||
|
||||
/* The variable argument pointer. */
|
||||
va_list ap;
|
||||
|
||||
/* Fetch the argument list. */
|
||||
va_start( ap, format );
|
||||
|
||||
/* Print the event. */
|
||||
line_current_pos += vsnprintf( log_lines[log_current_element] + line_current_pos, MAX_LOG_LINE_CHARS, format, ap );
|
||||
|
||||
/*
|
||||
if( level >= NWIPE_LOG_WARNING )
|
||||
{
|
||||
vfprintf( stderr, format, ap );
|
||||
}
|
||||
*/
|
||||
|
||||
/* Release the argument list. */
|
||||
va_end( ap );
|
||||
|
||||
/*
|
||||
if( level >= NWIPE_LOG_WARNING )
|
||||
{
|
||||
fprintf( stderr, "\n" );
|
||||
}
|
||||
*/
|
||||
|
||||
/* A result buffer. */
|
||||
int r;
|
||||
|
||||
/* The log file pointer. */
|
||||
FILE* fp;
|
||||
|
||||
/* The log file descriptor. */
|
||||
int fd;
|
||||
|
||||
|
||||
if (nwipe_options.logfile[0] == '\0')
|
||||
{
|
||||
if (nwipe_options.nogui)
|
||||
{
|
||||
printf( "%s\n", log_lines[log_current_element] );
|
||||
}
|
||||
else
|
||||
{
|
||||
log_current_element++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
/* Open the log file for appending. */
|
||||
fp = fopen( nwipe_options.logfile, "a" );
|
||||
|
||||
if( fp == NULL )
|
||||
{
|
||||
fprintf( stderr, "nwipe_log: Unable to open '%s' for logging.\n", nwipe_options.logfile );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the file descriptor of the log file. */
|
||||
fd = fileno( fp );
|
||||
|
||||
/* Block and lock. */
|
||||
r = flock( fd, LOCK_EX );
|
||||
|
||||
if( r != 0 )
|
||||
{
|
||||
perror( "nwipe_log: flock:" );
|
||||
fprintf( stderr, "nwipe_log: Unable to lock '%s' for logging.\n", nwipe_options.logfile );
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf( fp, "%s\n", log_lines[log_current_element] );
|
||||
|
||||
/* Unlock the file. */
|
||||
r = flock( fd, LOCK_UN );
|
||||
|
||||
if( r != 0 )
|
||||
{
|
||||
perror( "nwipe_log: flock:" );
|
||||
fprintf( stderr, "Error: Unable to unlock '%s' after logging.\n", nwipe_options.logfile );
|
||||
}
|
||||
|
||||
/* Close the stream. */
|
||||
r = fclose( fp );
|
||||
|
||||
if( r != 0 )
|
||||
{
|
||||
perror( "nwipe_log: fclose:" );
|
||||
fprintf( stderr, "Error: Unable to close '%s' after logging.\n", nwipe_options.logfile );
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock( &mutex1 );
|
||||
|
||||
|
||||
} /* nwipe_log */
|
||||
|
||||
|
||||
void nwipe_perror( int nwipe_errno, const char* f, const char* s )
|
||||
{
|
||||
/**
|
||||
* Wrapper for perror().
|
||||
*
|
||||
* We may wish to tweak or squelch this later.
|
||||
*
|
||||
*/
|
||||
|
||||
nwipe_log( NWIPE_LOG_ERROR, "%s: %s: %s", f, s, strerror( nwipe_errno ) );
|
||||
|
||||
} /* nwipe_perror */
|
||||
|
||||
/* eof */
|
||||
47
src/logging.h
Normal file
47
src/logging.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* logging.c: Logging facilities for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LOGGING_H_
|
||||
#define LOGGING_H_
|
||||
|
||||
typedef enum nwipe_log_t_
|
||||
{
|
||||
NWIPE_LOG_NONE = 0,
|
||||
NWIPE_LOG_DEBUG, /* TODO: Very verbose logging. */
|
||||
NWIPE_LOG_INFO, /* TODO: Verbose logging. */
|
||||
NWIPE_LOG_NOTICE, /* Most logging happens at this level. */
|
||||
NWIPE_LOG_WARNING, /* Things that the user should know about. */
|
||||
NWIPE_LOG_ERROR, /* Non-fatal errors that result in failure. */
|
||||
NWIPE_LOG_FATAL, /* Errors that cause the program to exit. */
|
||||
NWIPE_LOG_SANITY /* Programming errors. */
|
||||
} nwipe_log_t;
|
||||
|
||||
void nwipe_log( nwipe_log_t level, const char* format, ... );
|
||||
void nwipe_perror( int nwipe_errno, const char* f, const char* s );
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
//extern char **log_lines;
|
||||
//extern int log_current_element;
|
||||
//extern int log_elements_allocated;
|
||||
|
||||
#endif /* LOGGING_H_ */
|
||||
|
||||
/* eof */
|
||||
58
src/method.h
Normal file
58
src/method.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* methods.c: Method implementations for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef METHOD_H_
|
||||
#define METHOD_H_
|
||||
|
||||
/* The argument list for nwipe methods. */
|
||||
#define NWIPE_METHOD_SIGNATURE nwipe_context_t* c
|
||||
|
||||
typedef enum nwipe_verify_t_
|
||||
{
|
||||
NWIPE_VERIFY_NONE = 0, /* Do not read anything back from the device. */
|
||||
NWIPE_VERIFY_LAST, /* Check the last pass. */
|
||||
NWIPE_VERIFY_ALL, /* Check all passes. */
|
||||
} nwipe_verify_t;
|
||||
|
||||
/* The typedef of the function that will do the wipe. */
|
||||
typedef int(*nwipe_method_t)( void *ptr );
|
||||
|
||||
typedef struct /* nwipe_pattern_t */
|
||||
{
|
||||
int length; /* Length of the pattern in bytes, -1 means random. */
|
||||
char* s; /* The actual bytes of the pattern. */
|
||||
} nwipe_pattern_t;
|
||||
|
||||
const char* nwipe_method_label( void* method );
|
||||
int nwipe_runmethod( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* patterns );
|
||||
|
||||
void *nwipe_dod522022m( void *ptr );
|
||||
void *nwipe_dodshort( void *ptr );
|
||||
void *nwipe_gutmann( void *ptr );
|
||||
void *nwipe_ops2( void *ptr );
|
||||
void *nwipe_random( void *ptr );
|
||||
void *nwipe_zero( void *ptr );
|
||||
|
||||
#endif /* METHOD_H_ */
|
||||
|
||||
/* eof */
|
||||
139
src/mt19937ar-cok.c
Normal file
139
src/mt19937ar-cok.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
This code is modified for use in nwipe.
|
||||
|
||||
A C-program for MT19937, with initialization improved 2002/2/10.
|
||||
Coded by Takuji Nishimura and Makoto Matsumoto.
|
||||
This is a faster version by taking Shawn Cokus's optimization,
|
||||
Matthe Bellew's simplification, Isaku Wada's real version.
|
||||
|
||||
Before using, initialize the state by using init_genrand(seed)
|
||||
or init_by_array(init_key, key_length).
|
||||
|
||||
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of its contributors may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Any feedback is very welcome.
|
||||
http://www.math.keio.ac.jp/matumoto/emt.html
|
||||
email: matumoto@math.keio.ac.jp
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mt19937ar-cok.h"
|
||||
|
||||
/* initializes state[N] with a seed */
|
||||
void init_genrand( twister_state_t* state, unsigned long s)
|
||||
{
|
||||
int j;
|
||||
state->array[0]= s & 0xffffffffUL;
|
||||
for( j = 1; j < N; j++ )
|
||||
{
|
||||
state->array[j] = (1812433253UL * (state->array[j-1] ^ (state->array[j-1] >> 30)) + j);
|
||||
state->array[j] &= 0xffffffffUL; /* for >32 bit machines */
|
||||
}
|
||||
state->left = 1;
|
||||
state->initf = 1;
|
||||
}
|
||||
|
||||
|
||||
void twister_init( twister_state_t* state, unsigned long init_key[], unsigned long key_length )
|
||||
{
|
||||
int i = 1;
|
||||
int j = 0;
|
||||
int k = ( N > key_length ? N : key_length );
|
||||
|
||||
init_genrand( state, 19650218UL );
|
||||
|
||||
for( ; k; k-- )
|
||||
{
|
||||
state->array[i] = (state->array[i] ^ ((state->array[i-1] ^ (state->array[i-1] >> 30)) * 1664525UL)) + init_key[j] + j;
|
||||
state->array[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
||||
++i;
|
||||
++j;
|
||||
|
||||
if ( i >= N )
|
||||
{
|
||||
state->array[0] = state->array[N-1];
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if ( j >= key_length )
|
||||
{
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for( k = N -1; k; k-- )
|
||||
{
|
||||
state->array[i] = (state->array[i] ^ ((state->array[i-1] ^ (state->array[i-1] >> 30)) * 1566083941UL)) - i;
|
||||
state->array[i] &= 0xffffffffUL;
|
||||
++i;
|
||||
|
||||
if ( i >= N )
|
||||
{
|
||||
state->array[0] = state->array[N-1];
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
|
||||
state->array[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
||||
state->left = 1;
|
||||
state->initf = 1;
|
||||
}
|
||||
|
||||
static void next_state( twister_state_t* state )
|
||||
{
|
||||
unsigned long *p = state->array;
|
||||
int j;
|
||||
|
||||
if( state->initf == 0) { init_genrand( state, 5489UL ); }
|
||||
state->left = N;
|
||||
state->next = state->array;
|
||||
for( j = N - M + 1; --j; p++ ) { *p = p[M] ^ TWIST(p[0], p[1]); }
|
||||
for( j = M; --j; p++ ) { *p = p[M-N] ^ TWIST(p[0], p[1]); }
|
||||
*p = p[M-N] ^ TWIST(p[0], state->array[0]);
|
||||
}
|
||||
|
||||
/* generates a random number on [0,0xffffffff]-interval */
|
||||
unsigned long twister_genrand_int32( twister_state_t* state )
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if ( --state->left == 0 ) { next_state( state ); }
|
||||
y = *state->next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return y;
|
||||
}
|
||||
32
src/mt19937ar-cok.h
Normal file
32
src/mt19937ar-cok.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* mt19937ar-cok.h: The Mersenne Twister PRNG implementation for nwipe.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MT19937AR_H_
|
||||
#define MT19937AR_H_
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
||||
#define UMASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LMASK 0x7fffffffUL /* least significant r bits */
|
||||
#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
|
||||
#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
|
||||
|
||||
typedef struct twister_state_t_
|
||||
{
|
||||
unsigned long array[N];
|
||||
int left;
|
||||
int initf;
|
||||
unsigned long *next;
|
||||
} twister_state_t;
|
||||
|
||||
/* Initialize the MT state. ( 0 < key_length <= 624 ). */
|
||||
void twister_init( twister_state_t* state, unsigned long init_key[], unsigned long key_length);
|
||||
|
||||
/* Generate a random integer on the [0,0xffffffff] interval. */
|
||||
unsigned long twister_genrand_int32( twister_state_t* state );
|
||||
|
||||
#endif /* MT19937AR_H_ */
|
||||
@@ -91,7 +91,7 @@ int main( int argc, char** argv )
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
printf("Debug\n");
|
||||
argv += nwipe_optind;
|
||||
argc -= nwipe_optind;
|
||||
|
||||
@@ -577,7 +577,7 @@ void *signal_hand(void *ptr)
|
||||
}
|
||||
|
||||
// Kill the GUI thread
|
||||
/* DISABLE since it creates a segfault
|
||||
/* Needs to be FIXED(MVB)
|
||||
if( !nwipe_options.nogui )
|
||||
{
|
||||
if ( nwipe_misc_thread_data->gui_thread )
|
||||
|
||||
110
src/nwipe.h
Normal file
110
src/nwipe.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* nwipe.h: The header file of the nwipe program.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NWIPE_H_
|
||||
#define NWIPE_H_
|
||||
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
|
||||
/* workaround for Fedora */
|
||||
#ifndef off64_t
|
||||
# define off64_t off_t
|
||||
#endif
|
||||
|
||||
/* Busybox headers. */
|
||||
#ifdef BB_VER
|
||||
#include "busybox.h"
|
||||
#endif
|
||||
|
||||
/* System headers. */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <regex.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* System errors. */
|
||||
extern int errno;
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
extern char **log_lines;
|
||||
extern int log_current_element;
|
||||
extern int log_elements_allocated;
|
||||
extern pthread_mutex_t mutex1;
|
||||
|
||||
/* Ncurses headers. */
|
||||
#ifdef NCURSES_IN_SUBDIR
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#ifdef PANEL_IN_SUBDIR
|
||||
#include <ncurses/panel.h>
|
||||
#else
|
||||
#include <panel.h>
|
||||
#endif
|
||||
|
||||
/* Kernel device headers. */
|
||||
#include <linux/hdreg.h>
|
||||
|
||||
/* These types are usually defined in <asm/types.h> for __KERNEL__ code. */
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
/* This is required for ioctl BLKGETSIZE64, but it conflicts with <wait.h>. */
|
||||
/* #include <linux/fs.h> */
|
||||
|
||||
/* Define ioctls that cannot be included. */
|
||||
#define BLKSSZGET _IO(0x12,104)
|
||||
#define BLKBSZGET _IOR(0x12,112,size_t)
|
||||
#define BLKBSZSET _IOW(0x12,113,size_t)
|
||||
#define BLKGETSIZE64 _IOR(0x12,114,sizeof(u64))
|
||||
|
||||
/* This is required for ioctl FDFLUSH. */
|
||||
#include <linux/fd.h>
|
||||
|
||||
void *signal_hand(void *);
|
||||
|
||||
#endif /* NWIPE_H_ */
|
||||
|
||||
/* eof */
|
||||
68
src/options.h
Normal file
68
src/options.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* options.h: Command line processing routines for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OPTIONS_H_
|
||||
#define OPTIONS_H_
|
||||
|
||||
/* Program knobs. */
|
||||
#define NWIPE_KNOB_ENTROPY "/dev/urandom"
|
||||
#define NWIPE_KNOB_IDENTITY_SIZE 512
|
||||
#define NWIPE_KNOB_LABEL_SIZE 128
|
||||
#define NWIPE_KNOB_LOADAVG "/proc/loadavg"
|
||||
#define NWIPE_KNOB_LOG_BUFFERSIZE 1024 /* Maximum length of a log event. */
|
||||
#define NWIPE_KNOB_PARTITIONS "/proc/partitions"
|
||||
#define NWIPE_KNOB_PARTITIONS_PREFIX "/dev/"
|
||||
#define NWIPE_KNOB_PRNG_STATE_LENGTH 512 /* 128 words */
|
||||
#define NWIPE_KNOB_SCSI "/proc/scsi/scsi"
|
||||
#define NWIPE_KNOB_SLEEP 1
|
||||
#define NWIPE_KNOB_STAT "/proc/stat"
|
||||
|
||||
/* Function prototypes for loading options from the environment and command line. */
|
||||
int nwipe_options_parse( int argc, char** argv );
|
||||
void nwipe_options_log( void );
|
||||
|
||||
/* Function to display help text */
|
||||
void display_help();
|
||||
|
||||
typedef struct /* nwipe_options_t */
|
||||
{
|
||||
int autonuke; /* Do not prompt the user for confirmation when set. */
|
||||
int noblank; /* Do not perform a final blanking pass. */
|
||||
int nowait; /* Do not wait for a final key before exiting. */
|
||||
int nosignals; /* Do not allow signals to interrupt a wipe. */
|
||||
int nogui ; /* Do not show the GUI. */
|
||||
char* banner; /* The product banner shown on the top line of the screen. */
|
||||
// nwipe_method_t method; /* A function pointer to the wipe method that will be used. */
|
||||
void* method; /* A function pointer to the wipe method that will be used. */
|
||||
char logfile[FILENAME_MAX]; /* The filename to log the output to */
|
||||
nwipe_prng_t* prng; /* The pseudo random number generator implementation. */
|
||||
int rounds; /* The number of times that the wipe method should be called. */
|
||||
int sync; /* A flag to indicate whether writes should be sync'd. */
|
||||
nwipe_verify_t verify; /* A flag to indicate whether writes should be verified. */
|
||||
} nwipe_options_t;
|
||||
|
||||
extern nwipe_options_t nwipe_options;
|
||||
|
||||
#endif /* OPTIONS_H_ */
|
||||
|
||||
/* eof */
|
||||
35
src/pass.h
Normal file
35
src/pass.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* pass.h: Routines that read and write patterns to block devices.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* Modifications to original dwipe Copyright Andy Beverley <andy@andybev.com>
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PASS_H_
|
||||
#define PASS_H_
|
||||
|
||||
int nwipe_random_pass ( nwipe_context_t* c );
|
||||
int nwipe_random_verify( nwipe_context_t* c );
|
||||
int nwipe_static_pass ( nwipe_context_t* c, nwipe_pattern_t* pattern );
|
||||
int nwipe_static_verify( nwipe_context_t* c, nwipe_pattern_t* pattern );
|
||||
|
||||
void test_functionn( int count, nwipe_context_t** c );
|
||||
|
||||
#endif /* PASS_H_ */
|
||||
|
||||
/* eof */
|
||||
155
src/prng.c
Normal file
155
src/prng.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* prng.c: Pseudo Random Number Generator abstractions for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "nwipe.h"
|
||||
#include "prng.h"
|
||||
#include "logging.h"
|
||||
|
||||
#include "mt19937ar-cok.h"
|
||||
#include "isaac_rand.h"
|
||||
|
||||
|
||||
nwipe_prng_t nwipe_twister =
|
||||
{
|
||||
"Mersenne Twister (mt19937ar-cok)",
|
||||
nwipe_twister_init,
|
||||
nwipe_twister_read
|
||||
};
|
||||
|
||||
nwipe_prng_t nwipe_isaac =
|
||||
{
|
||||
"ISAAC (rand.c 20010626)",
|
||||
nwipe_isaac_init,
|
||||
nwipe_isaac_read
|
||||
};
|
||||
|
||||
|
||||
/* Print given number of bytes from unsigned integer number to a byte stream buffer starting with low-endian*/
|
||||
int nwipe_u32tobuffer(u8 *buffer, u32 rand, int len)
|
||||
{
|
||||
int i;
|
||||
u8 c; //single char
|
||||
if (len > sizeof(u32))
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Tried to print longer number than the value passed." );
|
||||
len = sizeof(u32);
|
||||
}
|
||||
|
||||
for (i=0 ; i < len; i++)
|
||||
{
|
||||
c=rand & 0xFFUL;
|
||||
rand = rand >> 8;
|
||||
buffer[i]=c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nwipe_twister_init( NWIPE_PRNG_INIT_SIGNATURE )
|
||||
{
|
||||
if( *state == NULL )
|
||||
{
|
||||
/* This is the first time that we have been called. */
|
||||
*state = malloc( sizeof( twister_state_t ) );
|
||||
}
|
||||
twister_init( (twister_state_t*)*state, (u32*)( seed->s ), seed->length / sizeof( u32 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nwipe_twister_read( NWIPE_PRNG_READ_SIGNATURE )
|
||||
{
|
||||
u32 i=0;
|
||||
u32 ii;
|
||||
u32 words = count / SIZE_OF_TWISTER ; // the values of twister_genrand_int32 is strictly 4 bytes
|
||||
u32 remain = count % SIZE_OF_TWISTER ; // the values of twister_genrand_int32 is strictly 4 bytes
|
||||
|
||||
/* Twister returns 4-bytes per call, so progress by 4 bytes. */
|
||||
for( ii = 0; ii < words; ++ii )
|
||||
{
|
||||
nwipe_u32tobuffer((u8*)(buffer+i), twister_genrand_int32( (twister_state_t*)*state ), SIZE_OF_TWISTER) ;
|
||||
i = i + SIZE_OF_TWISTER;
|
||||
}
|
||||
|
||||
/* If there is some remainder copy only relevant number of bytes to not
|
||||
* overflow the buffer. */
|
||||
if ( remain > 0 )
|
||||
{
|
||||
nwipe_u32tobuffer((u8*)(buffer+i), twister_genrand_int32( (twister_state_t*)*state ), remain) ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int nwipe_isaac_init( NWIPE_PRNG_INIT_SIGNATURE )
|
||||
{
|
||||
int count;
|
||||
randctx* isaac_state = *state;
|
||||
|
||||
if( *state == NULL )
|
||||
{
|
||||
/* This is the first time that we have been called. */
|
||||
*state = malloc( sizeof( randctx ) );
|
||||
isaac_state = *state;
|
||||
|
||||
/* Check the memory allocation. */
|
||||
if( isaac_state == 0 )
|
||||
{
|
||||
nwipe_perror( errno, __FUNCTION__, "malloc" );
|
||||
nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate memory for the isaac state." );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Take the minimum of the isaac seed size and available entropy. */
|
||||
if( sizeof( isaac_state->randrsl ) < seed->length )
|
||||
{
|
||||
count = sizeof( isaac_state->randrsl );
|
||||
}
|
||||
else
|
||||
{
|
||||
memset( isaac_state->randrsl, 0, sizeof( isaac_state->randrsl ) );
|
||||
count = seed->length;
|
||||
}
|
||||
|
||||
if( count == 0 )
|
||||
{
|
||||
/* Start ISACC without a seed. */
|
||||
randinit( isaac_state, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Seed the ISAAC state with entropy. */
|
||||
memcpy( isaac_state->randrsl, seed->s, count );
|
||||
|
||||
/* The second parameter indicates that randrsl is non-empty. */
|
||||
randinit( isaac_state, 1 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nwipe_isaac_read( NWIPE_PRNG_READ_SIGNATURE )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
60
src/prng.h
Normal file
60
src/prng.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* prng.h: Pseudo Random Number Generator abstractions for nwipe.
|
||||
*
|
||||
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
|
||||
*
|
||||
* 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, version 2.
|
||||
*
|
||||
* 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.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRNG_H_
|
||||
#define PRNG_H_
|
||||
|
||||
/* A chunk of random data. */
|
||||
typedef struct /* nwipe_entropy_t */
|
||||
{
|
||||
size_t length; /* Length of the entropy string in bytes. */
|
||||
u8* s; /* The actual bytes of the entropy string. */
|
||||
} nwipe_entropy_t;
|
||||
|
||||
#define NWIPE_PRNG_INIT_SIGNATURE void** state, nwipe_entropy_t* seed
|
||||
#define NWIPE_PRNG_READ_SIGNATURE void** state, void* buffer, size_t count
|
||||
|
||||
/* Function pointers for PRNG actions. */
|
||||
typedef int(*nwipe_prng_init_t)( NWIPE_PRNG_INIT_SIGNATURE );
|
||||
typedef int(*nwipe_prng_read_t)( NWIPE_PRNG_READ_SIGNATURE );
|
||||
|
||||
/* The generic PRNG definition. */
|
||||
typedef struct /* nwipe_prng_t */
|
||||
{
|
||||
const char* label; /* The name of the pseudo random number generator. */
|
||||
nwipe_prng_init_t init; /* Inialize the prng state with the seed. */
|
||||
nwipe_prng_read_t read; /* Read data from the prng. */
|
||||
} nwipe_prng_t;
|
||||
|
||||
/* Mersenne Twister prototypes. */
|
||||
int nwipe_twister_init( NWIPE_PRNG_INIT_SIGNATURE );
|
||||
int nwipe_twister_read( NWIPE_PRNG_READ_SIGNATURE );
|
||||
|
||||
/* ISAAC prototypes. */
|
||||
int nwipe_isaac_init( NWIPE_PRNG_INIT_SIGNATURE );
|
||||
int nwipe_isaac_read( NWIPE_PRNG_READ_SIGNATURE );
|
||||
|
||||
/* Size of the twister is not derived from the architecture, but it is strictly 4 bytes */
|
||||
#define SIZE_OF_TWISTER 4
|
||||
|
||||
|
||||
#endif /* PRNG_H_ */
|
||||
|
||||
/* eof */
|
||||
@@ -4,15 +4,7 @@
|
||||
* used by configure to dynamically assign those values
|
||||
* to documentation files.
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
const char *version_string = "0.20";
|
||||
=======
|
||||
const char *version_string = "0.18";
|
||||
>>>>>>> parent of 263d5d1... bump version to 0.19
|
||||
=======
|
||||
const char *version_string = "0.22";
|
||||
>>>>>>> e7d9ff73fe76e9fcc04847eba2806bd0904f0499
|
||||
const char *program_name = "nwipe";
|
||||
const char *author_name = "Martijn van Brummelen";
|
||||
const char *email_address = "git@brumit.nl";
|
||||
|
||||
Reference in New Issue
Block a user