16 Commits
1.0.8 ... 1.0.9

Author SHA1 Message Date
Jonas Stein
35b852cfeb add .clang-cormat
Add .clang-cormat config file to src folder for unified formatting.
2022-04-20 01:00:40 +02:00
Jonas Stein
88a507932e reformat and cleanup more
reformat the source in an unified way.
(improve later with clang-format config)
fix order of includes
use proper delete[] operator
2022-04-20 00:24:59 +02:00
Jonas Stein
aa2244308d cleaned code
removed std namespace
initialized variables
cleaned endl
added const for constants
tagged new version 1.0.8
2022-04-20 00:12:52 +02:00
Paweł Marciniak
e1e3676660 Use /dev/random to create a key (#22)
Co-authored-by: Paweł Marciniak <sunwire+git@gmail.com>
2022-04-19 22:16:37 +02:00
Jonas Stein
d4ffed77ab Create c-cpp.yml 2022-04-07 20:16:55 +02:00
Jonas Stein
82aca41962 do not make distbuilds anymore 2022-04-07 20:13:00 +02:00
Jonas Stein
b6b7cd90c0 Add LGTM Codeanalysis 2022-04-05 21:31:16 +02:00
John Coleman
e92ccb49ff Merge pull request #17 from fpiecka/patch-1
Remove duplicate zeroing
2020-11-13 20:11:27 -07:00
John Coleman
9feb3f8739 Merge pull request #23 from sunwire/spec
Add example spec file for Fedora/CentOS/RHEL
2020-11-13 20:10:40 -07:00
John Coleman
1dce245cce Merge pull request #25 from sunwire/license
Update GPL2 license
2020-11-13 20:10:18 -07:00
sunwire
b650fb67c0 Update URL from sf to github (#21)
* Correct url from sf to github

Co-authored-by: Paweł Marciniak <sunwire+git@gmail.com>
2020-11-13 00:25:23 +01:00
Paweł Marciniak
70859dfdaa Update GPL2 license 2020-11-11 14:29:13 +01:00
Paweł Marciniak
fc403b6267 Remove BuildRoot tag, add smp flags to make and license macro 2020-11-11 13:57:35 +01:00
Jonas Stein
aefb37e563 link IBM Tape Library Guide
Add link to documentation. 
IBM Tape Library Guide for Open Systems
2020-11-09 12:02:19 +01:00
Paweł Marciniak
90586aa018 Add example spec file for Fedora/CentOS/RHEL 2020-07-26 22:06:11 +02:00
Fedor Piecka
a4f407f361 Remove duplicate zeroing
memset zeroes whole &kad. No need to set it's parts to zero. Proposed in
2020-05-29 06:37:31 +02:00
13 changed files with 1706 additions and 1457 deletions

29
.github/workflows/c-cpp.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: C/C++ CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: autoconf
run: autoreconf -i
- name: configure
run: ./configure
- name: make
run: make
- name: make check
run: make check
- name: make distcheck
run: make distcheck
- name: make check
run: make check
- name: make distcheck
run: make distcheck

41
COPYING
View File

@@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The licenses for most software are designed to take away your The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public freedom to share and change it. By contrast, the GNU General Public
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to the GNU Lesser General Public License instead.) You can apply it to
your programs, too. your programs, too.
When we speak of free software, we are referring to freedom, not When we speak of free software, we are referring to freedom, not
@@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and The precise terms and conditions for copying, distribution and
modification follow. modification follow.
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains 0. This License applies to any program or other work which contains
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on does not normally print such an announcement, your work based on
the Program is not required to print an announcement.) the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program, identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in and can be reasonably considered independent and separate works in
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not distribution of the source code, even though third parties are not
compelled to copy the source along with the object code. compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is otherwise to copy, modify, sublicense or distribute the Program is
@@ -225,7 +225,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License. be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in 8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License original copyright holder who places the Program under this License
@@ -255,7 +255,7 @@ 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 preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally. of promoting the sharing and reuse of software generally.
NO WARRANTY NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS 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 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -277,9 +277,9 @@ 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 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest 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 possible use to the public, the best way to achieve this is to make it
@@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License along
along with this program; if not, write to the Free Software with this program; if not, write to the Free Software Foundation, Inc.,
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail. 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 If the program is interactive, make it output a short notice like this
when it starts in an interactive mode: when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
This General Public License does not permit incorporating your program into This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. Public License instead of this License.

View File

@@ -1,2 +1,2 @@
SUBDIRS = src man SUBDIRS = src man
EXTRA_DIST = buildconf # EXTRA_DIST = buildconf

View File

@@ -1,3 +1,6 @@
[![Total alerts](https://img.shields.io/lgtm/alerts/g/scsitape/stenc.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/scsitape/stenc/alerts/)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/scsitape/stenc.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/scsitape/stenc/context:cpp)
Stenc Stenc
----- -----
@@ -45,3 +48,9 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
Further reading
---------------
IBM Tape Library Guide for Open Systems
ISBN-13: 9780738458342
http://www.redbooks.ibm.com/abstracts/sg245946.html?Open

View File

@@ -1,4 +1,4 @@
AC_INIT([stenc], [1.0.8]) AC_INIT([stenc],[1.0.8])
AC_CONFIG_SRCDIR([src/main.cpp]) AC_CONFIG_SRCDIR([src/main.cpp])
AM_INIT_AUTOMAKE([foreign]) AM_INIT_AUTOMAKE([foreign])
@@ -9,7 +9,15 @@ AC_CHECK_HEADER([sys/machine.h])
AC_PROG_CXX AC_PROG_CXX
# Checks for header files. # Checks for header files.
AC_HEADER_STDC m4_warn([obsolete],
[The preprocessor macro `STDC_HEADERS' is obsolete.
Except in unusual embedded environments, you can safely include all
ISO C90 headers unconditionally.])dnl
# Autoupdate added the next two lines to ensure that your configure
# script's behavior did not change. They are probably safe to remove.
AC_CHECK_INCLUDES_DEFAULT
AC_PROG_EGREP
AC_MSG_CHECKING(whether to output raw SCSI messages) AC_MSG_CHECKING(whether to output raw SCSI messages)
@@ -93,5 +101,6 @@ fi
AC_OUTPUT(Makefile src/Makefile man/Makefile) AC_CONFIG_FILES([Makefile src/Makefile man/Makefile])
AC_OUTPUT

View File

@@ -27,7 +27,7 @@ Allows you to manage hardware encryption on SSP enabled tape devices (LTO4, LTO5
.SH OPTIONS .SH OPTIONS
.TP .TP
\fB\-g \fIlength\fR \fB\-k\fR \fB<file to save as>\fR [\fB\-kd\fR \fI<key descriptor(uKAD)>\fR] \fB\-g \fIlength\fR \fB\-k\fR \fB<file to save as>\fR [\fB\-kd\fR \fI<key descriptor(uKAD)>\fR]
Generates a key file of \fIlength\fR (in bits) containing a random hexadecimal key. After entering this option, you will be required to press random keys followed by the enter key. This will seed the random number generator so that your key is more secure. Specify the file to save the key into with the -k option (you will need write permissions to that file location). Lastly you can enter an optional key description using the -kd flag (see \fIKEY DESCRIPTORS\fR). This key file can then be used with the \fB\-k\fR option. You should not generate a key file over an unsecured remote session. Typically, key files should be set to 256 bits (32 hexadecimal bytes), however your device may only support 128 bits. Generates a key file of \fIlength\fR (in bits) containing a random hexadecimal key. After entering this option, you will be required to press random keys followed by the enter key. This will seed the random number generator so that your key is more secure. On systems with \fB/dev/random\fR, the key is automatically generated from the random content read from this file. Specify the file to save the key into with the -k option (you will need write permissions to that file location). Lastly you can enter an optional key description using the -kd flag (see \fIKEY DESCRIPTORS\fR). This key file can then be used with the \fB\-k\fR option. You should not generate a key file over an unsecured remote session. Typically, key files should be set to 256 bits (32 hexadecimal bytes), however your device may only support 128 bits.
.TP .TP
\fB\-f\fR \fIdevice\fR \fB\-f\fR \fIdevice\fR
@@ -116,7 +116,7 @@ Written by \fBJohn Coleman\fR and \fBSamuel Martinez Jr.\fR of SunWest Education
Report \fBstenc\fR bugs to \fIjcoleman1981@live.com\fR. Report \fBstenc\fR bugs to \fIjcoleman1981@live.com\fR.
.SH PROJECT UPDATES .SH PROJECT UPDATES
Visit \fBhttp://sourceforge.net/projects/stenc/\fR for more information. Visit \fBhttps://github.com/scsitape/stenc\fR for more information.
.SH COPYRIGHT .SH COPYRIGHT
Copyright 2012 contributing authors. License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Copyright 2012 contributing authors. License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

118
src/.clang-format Normal file
View File

@@ -0,0 +1,118 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

View File

@@ -1,123 +1,122 @@
#include <config.h>
#include <iostream>
#include <string.h>
#include <string>
#include <sstream>
#include "keyinfo.h" #include "keyinfo.h"
#include "scsiencrypt.h" #include "scsiencrypt.h"
using namespace std; #include <config.h>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>
Keyinfo::Keyinfo(){ Keyinfo::Keyinfo() {
valid=false; valid = false;
check=""; check = "";
key=NULL; key = NULL;
keySize=0; keySize = 0;
} }
void Keyinfo::load(string hexinput){ void Keyinfo::load(std::string hexinput) {
valid=true; valid = true;
if(hexinput.size()<2){ if (hexinput.size() < 2) {
valid=false; valid = false;
cout<<"Key input too short!"<<endl; std::cout << "Key input too short!\n";
return; return;
}
} // parse for invalid characters
//parse for invalid characters for (unsigned int i = 0; i < hexinput.size(); i++) {
for(unsigned int i=0;i<hexinput.size();i++){ switch ((unsigned char)hexinput.at(i)) {
switch((unsigned char)hexinput.at(i)){ case '0':
case '0': case '1':
case '1': case '2':
case '2': case '3':
case '3': case '4':
case '4': case '5':
case '5': case '6':
case '6': case '7':
case '7': case '8':
case '8': case '9':
case '9': case 'a':
case 'a': case 'b':
case 'b': case 'c':
case 'c': case 'd':
case 'd': case 'e':
case 'e': case 'f':
case 'f': case 'A':
case 'A': case 'B':
case 'B': case 'C':
case 'C': case 'D':
case 'D': case 'E':
case 'E': case 'F':
case 'F': break;
break; default:
default: std::cout << "Invalid character '" << hexinput.at(i)
cout<<"Invalid character '"<<hexinput.at(i)<<"' found in key!"<<endl; << "' found in key!\n";
valid=false; valid = false;
return; return;
} }
} }
// delete the key if its already allocated // delete the key if its already allocated
if(key!=NULL) if (key != NULL)
delete key; delete[] key;
// check that the input size is divisible by 2 // check that the input size is divisible by 2
if(hexinput.size()%2!=0){ if (hexinput.size() % 2 != 0) {
valid=false; valid = false;
cout<<"Each hexadecimal byte must consist of 2 digits!"<<endl; std::cout << "Each hexadecimal byte must consist of 2 digits!\n";
return; return;
} }
//convert the hex input to a char* // convert the hex input to a char*
loadKey(hexinput); loadKey(hexinput);
//load the check value // load the check value
loadCheck(); loadCheck();
//check for oversized key // check for oversized key
if(keySize==0 || keySize>SSP_KEY_LENGTH){ if (keySize == 0 || keySize > SSP_KEY_LENGTH) {
cout<<"Key size cannot exceed "<<(SSP_KEY_LENGTH*8)<<" bits!"<<endl; std::cout << "Key size cannot exceed " << (SSP_KEY_LENGTH * 8)
cout<<"Provided key is "<<(keySize*8)<<" bits in length."<<endl; << " bits!\n";
valid=false; std::cout << "Provided key is " << (keySize * 8) << " bits in length.\n";
return; valid = false;
} return;
cout<<"Provided key length is "<<(keySize*8)<<" bits."<<endl; }
cout<<"Key checksum is "<<check<<"."<<endl; std::cout << "Provided key length is " << (keySize * 8) << " bits.\n";
std::cout << "Key checksum is " << check << ".\n";
} }
void Keyinfo::loadCheck() { void Keyinfo::loadCheck() {
int i; int i;
int chk = 0; int chk = 0;
for (i = 0; i<keySize;i++) { for (i = 0; i < keySize; i++) {
chk += ((int)key[i]) * (i + 1); chk += ((int)key[i]) * (i + 1);
} }
stringstream retval; std::stringstream retval;
retval<<hex<<chk; retval << std::hex << chk;
check=retval.str(); check = retval.str();
} }
Keyinfo::~Keyinfo(){ Keyinfo::~Keyinfo() { delete[] key; }
delete key; void Keyinfo::loadKey(std::string str) {
} int length = str.size();
void Keyinfo::loadKey(string str) // make sure the input string has an even digit numbers
{ if (length % 2 == 1) {
int length = str.size(); str = "0" + str;
// make sure the input string has an even digit numbers length++;
if(length%2 == 1) }
{
str = "0" + str;
length++;
}
// allocate memory for the output array // allocate memory for the output array
key = new char[length/2]; key = new char[length / 2];
memset(key,0,(length/2)+1); memset(key, 0, (length / 2) + 1);
keySize = length/2; keySize = length / 2;
stringstream sstr(str); std::stringstream sstr(str);
for(int i=0; i < keySize; i++) for (int i = 0; i < keySize; i++) {
{ char ch1, ch2;
char ch1, ch2; sstr >> ch1 >> ch2;
sstr >> ch1 >> ch2; int dig1 = 0, dig2 = 0;
int dig1=0, dig2=0; if (isdigit(ch1))
if(isdigit(ch1)) dig1 = ch1 - '0'; dig1 = ch1 - '0';
else if(ch1>='A' && ch1<='F') dig1 = ch1 - 'A' + 10; else if (ch1 >= 'A' && ch1 <= 'F')
else if(ch1>='a' && ch1<='f') dig1 = ch1 - 'a' + 10; dig1 = ch1 - 'A' + 10;
if(isdigit(ch2)) dig2 = ch2 - '0'; else if (ch1 >= 'a' && ch1 <= 'f')
else if(ch2>='A' && ch2<='F') dig2 = ch2 - 'A' + 10; dig1 = ch1 - 'a' + 10;
else if(ch2>='a' && ch2<='f') dig2 = ch2 - 'a' + 10; if (isdigit(ch2))
key[i] = dig1*16 + dig2; dig2 = ch2 - '0';
} else if (ch2 >= 'A' && ch2 <= 'F')
dig2 = ch2 - 'A' + 10;
else if (ch2 >= 'a' && ch2 <= 'f')
dig2 = ch2 - 'a' + 10;
key[i] = dig1 * 16 + dig2;
}
} }

View File

@@ -2,19 +2,19 @@
#define KEYINFO_H #define KEYINFO_H
#include <string> #include <string>
class Keyinfo{ class Keyinfo {
public: public:
char* key; char *key;
int keySize; int keySize;
bool valid; bool valid;
std::string check; std::string check;
void load(std::string hexinput); void load(std::string hexinput);
Keyinfo(); Keyinfo();
~Keyinfo(); ~Keyinfo();
private:
void loadKey(std::string str); private:
void loadCheck(); void loadKey(std::string str);
void loadCheck();
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -15,350 +15,346 @@ GNU General Public License for more details.
#ifndef _SCSIENC_H #ifndef _SCSIENC_H
#define _SCSIENC_H #define _SCSIENC_H
#include <string>
#include <bitset> #include <bitset>
#include <string>
#include <vector> #include <vector>
#define SSP_KEY_LENGTH 0X20 #define SSP_KEY_LENGTH 0X20
#define SSP_DESCRIPTOR_LENGTH 1024 #define SSP_DESCRIPTOR_LENGTH 1024
#define SSP_PAGE_DES_LENGTH 24 #define SSP_PAGE_DES_LENGTH 24
#define SSP_PAGE_NBES_LENGTH 16 #define SSP_PAGE_NBES_LENGTH 16
#define SSP_KAD_HEAD_LENGTH 4 #define SSP_KAD_HEAD_LENGTH 4
#define SSP_PAGE_ALLOCATION 8192 #define SSP_PAGE_ALLOCATION 8192
#define SSP_UKAD_LENGTH 0x1e #define SSP_UKAD_LENGTH 0x1e
#define KAD_TYPE_UKAD 0x00 #define KAD_TYPE_UKAD 0x00
#define KAD_TYPE_AKAD 0x01 #define KAD_TYPE_AKAD 0x01
#define KAD_TYPE_NONCE 0x02 #define KAD_TYPE_NONCE 0x02
#define KAD_TYPE_META 0x03 #define KAD_TYPE_META 0x03
#define RDMC_PROTECT 0x03 #define RDMC_PROTECT 0x03
#define RDMC_UNPROTECT 0x02 #define RDMC_UNPROTECT 0x02
#define RDMC_DEFAULT 0x00 #define RDMC_DEFAULT 0x00
//outputs hex in a 2 digit pair // outputs hex in a 2 digit pair
#define HEX( x ) right<<setw(2)<< setfill('0') << hex << (int)( x )<<setfill(' ') #define HEX(x) \
//macro for a byte swapped short right << setw(2) << setfill('0') << hex << (int)(x) << setfill(' ')
#define BSSHORT( x ) ((unsigned short)( (x[0]<<8) + x[1] )) // macro for a byte swapped short
//macro for a byte swapped int #define BSSHORT(x) ((unsigned short)((x[0] << 8) + x[1]))
#define BSLONG( x ) ((unsigned int)( (int)( x[0] << 24 ) + (int)( x[1] << 16 ) + (int)( x[2] << 8 ) + (int)( x[3] ) )) // macro for a byte swapped int
#define BSLONG(x) \
((unsigned int)((int)(x[0] << 24) + (int)(x[1] << 16) + (int)(x[2] << 8) + \
(int)(x[3])))
#ifdef HAVE_SYS_MACHINE_H #ifdef HAVE_SYS_MACHINE_H
#include <sys/machine.h> #include <sys/machine.h>
#endif #endif
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#ifdef BYTE_ORDER #ifdef BYTE_ORDER
#define STENC_BYTE_ORDER BYTE_ORDER #define STENC_BYTE_ORDER BYTE_ORDER
#endif #endif
#ifndef STENC_BYTE_ORDER #ifndef STENC_BYTE_ORDER
#ifdef __BYTE_ORDER #ifdef __BYTE_ORDER
#define STENC_BYTE_ORDER __BYTE_ORDER #define STENC_BYTE_ORDER __BYTE_ORDER
#endif #endif
#endif #endif
#ifdef BIG_ENDIAN #ifdef BIG_ENDIAN
#define STENC_TYPE_BIG_ENDIAN BIG_ENDIAN #define STENC_TYPE_BIG_ENDIAN BIG_ENDIAN
#endif #endif
#ifndef STENC_TYPE_BIG_ENDIAN #ifndef STENC_TYPE_BIG_ENDIAN
#ifdef __BIG_ENDIAN #ifdef __BIG_ENDIAN
#define STENC_TYPE_BIG_ENDIAN __BIG_ENDIAN #define STENC_TYPE_BIG_ENDIAN __BIG_ENDIAN
#endif #endif
#endif #endif
#if STENC_BYTE_ORDER == STENC_TYPE_BIG_ENDIAN #if STENC_BYTE_ORDER == STENC_TYPE_BIG_ENDIAN
#define STENC_BIG_ENDIAN 1 #define STENC_BIG_ENDIAN 1
#else #else
#define STENC_BIG_ENDIAN 0 #define STENC_BIG_ENDIAN 0
#endif #endif
typedef struct { typedef struct {
unsigned char pageCode [2]; unsigned char pageCode[2];
unsigned char length [2]; unsigned char length[2];
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char nexusScope :3; unsigned char nexusScope : 3;
unsigned char res_bits_1 :2; unsigned char res_bits_1 : 2;
unsigned char keyScope :3; unsigned char keyScope : 3;
#else #else
unsigned char keyScope :3; unsigned char keyScope : 3;
unsigned char res_bits_1 :2; unsigned char res_bits_1 : 2;
unsigned char nexusScope :3; unsigned char nexusScope : 3;
#endif #endif
unsigned char encryptionMode; unsigned char encryptionMode;
unsigned char decryptionMode; unsigned char decryptionMode;
unsigned char algorithmIndex; unsigned char algorithmIndex;
unsigned char keyInstance [4]; unsigned char keyInstance[4];
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char res_bits_2 :1; unsigned char res_bits_2 : 1;
unsigned char parametersControl :3; unsigned char parametersControl : 3;
unsigned char VCELB :1; unsigned char VCELB : 1;
unsigned char CEEMS :2; unsigned char CEEMS : 2;
unsigned char RDMD :1; unsigned char RDMD : 1;
#else #else
unsigned char RDMD :1;
unsigned char CEEMS :2;
unsigned char VCELB :1;
unsigned char parametersControl :3;
unsigned char res_bits_2 :1;
#endif
unsigned char res_bits_3;
unsigned char ASDKCount [2];
unsigned char res_bits_4 [8];
} SSP_PAGE_DES; //device encryption status page unsigned char RDMD : 1;
unsigned char CEEMS : 2;
unsigned char VCELB : 1;
unsigned char parametersControl : 3;
unsigned char res_bits_2 : 1;
#endif
unsigned char res_bits_3;
unsigned char ASDKCount[2];
unsigned char res_bits_4[8];
} SSP_PAGE_DES; // device encryption status page
typedef struct { typedef struct {
unsigned char type; unsigned char type;
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char res_bits_1 :5; unsigned char res_bits_1 : 5;
unsigned char authenticated :3; unsigned char authenticated : 3;
#else #else
unsigned char authenticated :3; unsigned char authenticated : 3;
unsigned char res_bits_1 :5; unsigned char res_bits_1 : 5;
#endif #endif
unsigned char descriptorLength [2]; unsigned char descriptorLength[2];
unsigned char descriptor [SSP_DESCRIPTOR_LENGTH]; //will actually be the size of descriptorLength unsigned char descriptor[SSP_DESCRIPTOR_LENGTH]; // will actually be the size
// of descriptorLength
} SSP_KAD; } SSP_KAD;
typedef struct{ typedef struct {
unsigned char pageCode [2]; unsigned char pageCode[2];
unsigned char length [2]; unsigned char length[2];
unsigned char buffer [SSP_PAGE_ALLOCATION]; unsigned char buffer[SSP_PAGE_ALLOCATION];
} SSP_PAGE_BUFFER; //generic ssp page buffer } SSP_PAGE_BUFFER; // generic ssp page buffer
typedef struct { typedef struct {
unsigned char pageCode [2]; unsigned char pageCode[2];
unsigned char length [2]; unsigned char length[2];
unsigned char log_obj_num [8]; unsigned char log_obj_num[8];
#if STENC_BIG_ENDIAN == 1
unsigned char compressionStatus :4;
unsigned char encryptionStatus :4;
#else
unsigned char encryptionStatus :4;
unsigned char compressionStatus :4;
#endif
unsigned char algorithmIndex;
#if STENC_BIG_ENDIAN == 1
unsigned char res_bits_1 :6;
unsigned char EMES :1;
unsigned char RDMDS :1;
#else
unsigned char RDMDS :1;
unsigned char EMES :1;
unsigned char res_bits_1 :6;
#endif
unsigned char res_bits_2;
} SSP_PAGE_NBES; //next block encryption status page
typedef struct{
#if STENC_BIG_ENDIAN == 0
unsigned char peripheralQualifier :3;
unsigned char periphrealDeviceType :5;
#else
unsigned char periphrealDeviceType :5;
unsigned char peripheralQualifier :3;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char RMB :1;
unsigned char res_bits_1 :7;
#else
unsigned char res_bits_1 :7;
unsigned char RMB :1;
#endif
unsigned char Version [1];
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_1 :2;
unsigned char NORMACA :1;
unsigned char HISUP :1;
unsigned char responseDataFormat :4;
#else
unsigned char responseDataFormat :4;
unsigned char HISUP :1;
unsigned char NORMACA :1;
unsigned char obs_bits_1 :2;
#endif
unsigned char additionalLength [1];
#if STENC_BIG_ENDIAN == 0
unsigned char SCCS :1;
unsigned char ACC :1;
unsigned char TPGS :2;
unsigned char threePC :1;
unsigned char res_bits_2 :2;
unsigned char protect :1;
#else
unsigned char protect :1;
unsigned char res_bits_2 :2;
unsigned char threePC :1;
unsigned char TPGS :2;
unsigned char ACC :1;
unsigned char SCCS :1;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_2 :1;
unsigned char ENCSERV :1;
unsigned char VS :1;
unsigned char MULTIP :1;
unsigned char MCHNGR :1;
unsigned char obs_bits_3 :2;
unsigned char ADDR16 :1;
#else
unsigned char ADDR16 :1;
unsigned char obs_bits_3 :2;
unsigned char MCHNGR :1;
unsigned char MULTIP :1;
unsigned char VS :1;
unsigned char ENCSERV :1;
unsigned char obs_bits_2 :1;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_4 :2;
unsigned char WBUS16 :1;
unsigned char SYNC :1;
unsigned char obs_bits_5 :2;
unsigned char CMDQUE :1;
unsigned char VS2 :1;
#else
unsigned char VS2 :1;
unsigned char CMDQUE :1;
unsigned char obs_bits_5 :2;
unsigned char SYNC :1;
unsigned char WBUS16 :1;
unsigned char obs_bits_4 :2;
#endif
unsigned char vender [8];
unsigned char productID [16];
unsigned char productRev [4];
unsigned char SN [7];
unsigned char venderUnique [12];
#if STENC_BIG_ENDIAN == 0
unsigned char res_bits_3 :4;
unsigned char CLOCKING :2;
unsigned char QAS :1;
unsigned char IUS :1;
#else
unsigned char IUS :1;
unsigned char QAS :1;
unsigned char CLOCKING :2;
unsigned char res_bits_3 :4;
#endif
unsigned char res_bits_4 [1];
unsigned char versionDescriptor [16];
unsigned char res_bits_5 [22];
unsigned char copyright [1];
} SCSI_PAGE_INQ; //device inquiry response
typedef struct{
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char valid :1; unsigned char compressionStatus : 4;
unsigned char responseCode :7; unsigned char encryptionStatus : 4;
#else #else
unsigned char responseCode :7; unsigned char encryptionStatus : 4;
unsigned char valid :1; unsigned char compressionStatus : 4;
#endif #endif
unsigned char res_bits_1;
unsigned char algorithmIndex;
#if STENC_BIG_ENDIAN == 1
unsigned char res_bits_1 : 6;
unsigned char EMES : 1;
unsigned char RDMDS : 1;
#else
unsigned char RDMDS : 1;
unsigned char EMES : 1;
unsigned char res_bits_1 : 6;
#endif
unsigned char res_bits_2;
} SSP_PAGE_NBES; // next block encryption status page
typedef struct {
#if STENC_BIG_ENDIAN == 0
unsigned char peripheralQualifier : 3;
unsigned char periphrealDeviceType : 5;
#else
unsigned char periphrealDeviceType : 5;
unsigned char peripheralQualifier : 3;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char RMB : 1;
unsigned char res_bits_1 : 7;
#else
unsigned char res_bits_1 : 7;
unsigned char RMB : 1;
#endif
unsigned char Version[1];
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_1 : 2;
unsigned char NORMACA : 1;
unsigned char HISUP : 1;
unsigned char responseDataFormat : 4;
#else
unsigned char responseDataFormat : 4;
unsigned char HISUP : 1;
unsigned char NORMACA : 1;
unsigned char obs_bits_1 : 2;
#endif
unsigned char additionalLength[1];
#if STENC_BIG_ENDIAN == 0
unsigned char SCCS : 1;
unsigned char ACC : 1;
unsigned char TPGS : 2;
unsigned char threePC : 1;
unsigned char res_bits_2 : 2;
unsigned char protect : 1;
#else
unsigned char protect : 1;
unsigned char res_bits_2 : 2;
unsigned char threePC : 1;
unsigned char TPGS : 2;
unsigned char ACC : 1;
unsigned char SCCS : 1;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_2 : 1;
unsigned char ENCSERV : 1;
unsigned char VS : 1;
unsigned char MULTIP : 1;
unsigned char MCHNGR : 1;
unsigned char obs_bits_3 : 2;
unsigned char ADDR16 : 1;
#else
unsigned char ADDR16 : 1;
unsigned char obs_bits_3 : 2;
unsigned char MCHNGR : 1;
unsigned char MULTIP : 1;
unsigned char VS : 1;
unsigned char ENCSERV : 1;
unsigned char obs_bits_2 : 1;
#endif
#if STENC_BIG_ENDIAN == 0
unsigned char obs_bits_4 : 2;
unsigned char WBUS16 : 1;
unsigned char SYNC : 1;
unsigned char obs_bits_5 : 2;
unsigned char CMDQUE : 1;
unsigned char VS2 : 1;
#else
unsigned char VS2 : 1;
unsigned char CMDQUE : 1;
unsigned char obs_bits_5 : 2;
unsigned char SYNC : 1;
unsigned char WBUS16 : 1;
unsigned char obs_bits_4 : 2;
#endif
unsigned char vender[8];
unsigned char productID[16];
unsigned char productRev[4];
unsigned char SN[7];
unsigned char venderUnique[12];
#if STENC_BIG_ENDIAN == 0
unsigned char res_bits_3 : 4;
unsigned char CLOCKING : 2;
unsigned char QAS : 1;
unsigned char IUS : 1;
#else
unsigned char IUS : 1;
unsigned char QAS : 1;
unsigned char CLOCKING : 2;
unsigned char res_bits_3 : 4;
#endif
unsigned char res_bits_4[1];
unsigned char versionDescriptor[16];
unsigned char res_bits_5[22];
unsigned char copyright[1];
} SCSI_PAGE_INQ; // device inquiry response
typedef struct {
#if STENC_BIG_ENDIAN == 1
unsigned char valid : 1;
unsigned char responseCode : 7;
#else
unsigned char responseCode : 7;
unsigned char valid : 1;
#endif
unsigned char res_bits_1;
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char filemark :1; unsigned char filemark : 1;
unsigned char EOM :1; unsigned char EOM : 1;
unsigned char ILI :1; unsigned char ILI : 1;
unsigned char res_bits_2 :1; unsigned char res_bits_2 : 1;
unsigned char senseKey :4; unsigned char senseKey : 4;
#else #else
unsigned char senseKey :4; unsigned char senseKey : 4;
unsigned char res_bits_2 :1; unsigned char res_bits_2 : 1;
unsigned char ILI :1; unsigned char ILI : 1;
unsigned char EOM :1; unsigned char EOM : 1;
unsigned char filemark :1; unsigned char filemark : 1;
#endif #endif
unsigned char information [4]; unsigned char information[4];
unsigned char addSenseLen; unsigned char addSenseLen;
unsigned char cmdSpecificInfo [4]; unsigned char cmdSpecificInfo[4];
unsigned char addSenseCode; unsigned char addSenseCode;
unsigned char addSenseCodeQual; unsigned char addSenseCodeQual;
unsigned char fieldRepUnitCode; unsigned char fieldRepUnitCode;
#if STENC_BIG_ENDIAN == 1 #if STENC_BIG_ENDIAN == 1
unsigned char sim :3; // system information message unsigned char sim : 3; // system information message
unsigned char bpv :1; // bit pointer valid unsigned char bpv : 1; // bit pointer valid
unsigned char resvd2 :2; // reserved unsigned char resvd2 : 2; // reserved
unsigned char cd :1; // control/data unsigned char cd : 1; // control/data
unsigned char SKSV :1; unsigned char SKSV : 1;
#else #else
unsigned char SKSV :1; unsigned char SKSV : 1;
unsigned char cd :1; // control/data unsigned char cd : 1; // control/data
unsigned char resvd2 :2; // reserved unsigned char resvd2 : 2; // reserved
unsigned char bpv :1; // bit pointer valid unsigned char bpv : 1; // bit pointer valid
unsigned char sim :3; // system information message unsigned char sim : 3; // system information message
#endif #endif
unsigned char field [2]; // field pointer unsigned char field[2]; // field pointer
unsigned char addSenseData [109]; unsigned char addSenseData[109];
} SCSI_PAGE_SENSE; //sense data response } SCSI_PAGE_SENSE; // sense data response
class KAD_CLASS{ class KAD_CLASS {
public: public:
std::vector<SSP_KAD> kads; std::vector<SSP_KAD> kads;
protected:
void loadKADs(SSP_PAGE_BUFFER* buffer, int start); protected:
void loadKADs(SSP_PAGE_BUFFER *buffer, int start);
}; };
// class used to parse next block encryption status page
//class used to parse next block encryption status page class SSP_NBES : public KAD_CLASS {
class SSP_NBES: public KAD_CLASS{ public:
public: SSP_PAGE_NBES nbes;
SSP_PAGE_NBES nbes; SSP_NBES(SSP_PAGE_BUFFER *buffer);
SSP_NBES(SSP_PAGE_BUFFER* buffer);
}; };
//class used to parse data encryption status page // class used to parse data encryption status page
class SSP_DES: public KAD_CLASS{ class SSP_DES : public KAD_CLASS {
public: public:
SSP_PAGE_DES des; SSP_PAGE_DES des;
SSP_DES(SSP_PAGE_BUFFER* buffer); SSP_DES(SSP_PAGE_BUFFER *buffer);
}; };
// enum for SCSIEncryptOptions.cryptMode
enum { CRYPTMODE_OFF, CRYPTMODE_MIXED, CRYPTMODE_ON, CRYPTMODE_RAWREAD };
//enum for SCSIEncryptOptions.cryptMode // used to pass parameters to SCSIWriteEncryptOptions
enum { CRYPTMODE_OFF, CRYPTMODE_MIXED,CRYPTMODE_ON,CRYPTMODE_RAWREAD};
//used to pass parameters to SCSIWriteEncryptOptions
class SCSIEncryptOptions { class SCSIEncryptOptions {
public: public:
int rdmc; int rdmc;
bool CKOD; bool CKOD;
int cryptMode; int cryptMode;
unsigned int algorithmIndex; unsigned int algorithmIndex;
std::string cryptoKey; std::string cryptoKey;
std::string keyName; std::string keyName;
SCSIEncryptOptions(); SCSIEncryptOptions();
}; };
//Gets encryption options on the tape drive // Gets encryption options on the tape drive
SSP_DES* SSPGetDES(std::string tapeDevice); SSP_DES *SSPGetDES(std::string tapeDevice);
//Gets the encryption status from the tape volume // Gets the encryption status from the tape volume
SSP_NBES* SSPGetNBES(std::string tapeDevice,bool retry); SSP_NBES *SSPGetNBES(std::string tapeDevice, bool retry);
//Writes encryption options to the tape drive // Writes encryption options to the tape drive
bool SCSIWriteEncryptOptions(std::string tapeDevice, SCSIEncryptOptions* eOptions); bool SCSIWriteEncryptOptions(std::string tapeDevice,
//Gets device inquiry SCSIEncryptOptions *eOptions);
SCSI_PAGE_INQ* SCSIGetInquiry(std::string tapeDevice); // Gets device inquiry
SCSI_PAGE_INQ *SCSIGetInquiry(std::string tapeDevice);
#endif #endif

50
stenc.spec Normal file
View File

@@ -0,0 +1,50 @@
Name: stenc
Version: 1.0.9
Release: 3%{?dist}
Summary: SCSI Tape Encryption Manager
License: GPLv2
URL: https://github.com/scsitape/stenc
Source0: https://github.com/scsitape/stenc/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
BuildRequires: gcc-c++
BuildRequires: make
BuildRequires: autoconf
BuildRequires: automake
%description
SCSI Tape Encryption Manager - Manages encryption on LTO 4 and newer tape
drives with hardware-based encryption
%prep
%setup -q
%build
./autogen.sh
%configure
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%license COPYING
%doc README.md AUTHORS
%{_bindir}/stenc
%{_mandir}/man1/stenc.1*
%changelog
* Wed Nov 11 2020 Paweł Marciniak <sunwire+repo@gmail.com> - 1.0.8-3
- Remove BuildRoot tag, add smp flags to make and license macro
* Sat Nov 07 2020 Paweł Marciniak <sunwire+repo@gmail.com> - 1.0.8-2
- Make will no longer be in BuildRoot by default
* Sat Jul 4 2020 Paweł Marciniak <sunwire+repo@gmail.com> 1.0.8-1
- Initial SPEC file