From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29030 invoked by alias); 10 Jun 2015 20:32:05 -0000 Mailing-List: contact cygwin-apps-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-apps-cvs-owner@sourceware.org Received: (qmail 29009 invoked by uid 10076); 10 Jun 2015 20:32:05 -0000 Date: Wed, 10 Jun 2015 20:32:00 -0000 Message-ID: <20150610203205.28983.qmail@sourceware.org> From: gratz@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [setup] branch master, updated. release_2.871-1-g3ce2ac3 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 8648b05caf47865394d76822dea7b37e5cc1282e X-Git-Newrev: 3ce2ac3109f7acb38491b74bd48751ef76eae42c X-SW-Source: 2015-q2/txt/msg00004.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-setup.git;h=3ce2ac3109f7acb38491b74bd48751ef76eae42c commit 3ce2ac3109f7acb38491b74bd48751ef76eae42c Author: Achim Gratz Date: Sun Jun 7 09:10:13 2015 +0200 Implement Base64URL-encoded SHA512 checksums * ini.h: Add macros for use within the implementation of the checksum parsers. Hexdigest requires a 2-to-1 and Base64 a 4-to-3 conversion. Base64 uses the filename and URL safe alphabet from RFC4648. It would be trivial to additionally process the normal Base64 alphabet but we don't want to allow that in order to be able to use the checksums as filenames without further conversion. (hexnibble, b64url): Process single input character to input value. (nibbled1): Convert 2 processed input values into 1 output value. (b64d1, b64d2, b64d3): Convert 4 input values into 3 output values. * iniparse.yy: Add SHA512B64URL checksum in addition to MD5 and SHA512. Keep symmetry with MD5LINE and also define SHA512LINE syntax. * inilex.ll: Implement existing MD5 and SHA512 checksum parsers using new macros. Implement new SHA512B64URL parser using new macros. Enforce Base64 alphabet as defined in RFC4648 with no padding to enable direct use of checksum values as filenames. Implement SHA512LINE parser. Diff: --- ChangeLog | 21 +++++++++++++++++++++ ini.h | 14 ++++++++++++++ inilex.ll | 55 +++++++++++++++++++++++++++++++++++++++---------------- iniparse.yy | 9 +++++++-- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 854ba05..b2b3ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2015-06-07 Achim Gratz + + * ini.h: Add macros for use within the implementation of the + checksum parsers. Hexdigest requires a 2-to-1 and Base64 a 4-to-3 + conversion. Base64 uses the filename and URL safe alphabet from + RFC4648. It would be trivial to additionally process the normal + Base64 alphabet but we don't want to allow that in order to be + able to use the checksums as filenames without further conversion. + (hexnibble, b64url): Process single input character to input value. + (nibbled1): Convert 2 processed input values into 1 output value. + (b64d1, b64d2, b64d3): Convert 4 input values into 3 output + values. + * iniparse.yy: Add SHA512B64URL checksum in addition to MD5 and + SHA512. Keep symmetry with MD5LINE and also define SHA512LINE + syntax. + * inilex.ll: Implement existing MD5 and SHA512 checksum parsers + using new macros. Implement new SHA512B64URL parser using new + macros. Enforce Base64 alphabet as defined in RFC4648 with no + padding to enable direct use of checksum values as filenames. + Implement SHA512LINE parser. + 2015-03-25 Corinna Vinschen * install.cc (sha512_one): Raise buffer size to 64K for performance diff --git a/ini.h b/ini.h index 232c600..ec09def 100644 --- a/ini.h +++ b/ini.h @@ -52,4 +52,18 @@ extern std::string current_ini_sig_name; /* current filename/URL for sig file * extern std::string yyerror_messages; /* textual parse error messages */ extern int yyerror_count; /* number of parse errors */ +/* The following definitions are used in the parser implementation */ + +#define hexnibble(val) (255 & (val > '9') ? val - 'a' + 10 : val - '0'); +#define nibbled1(v1,v2) (255 & ((v1 << 4) & v2)); +#define b64url(val) \ + (63 & (( val == '_') ? 63 \ + : (val == '-') ? 62 \ + : (val >= 'a') ? val - 'a' + 26 \ + : (val >= 'A') ? val - 'A' + 0 \ + : val - '0' + 52)) +#define b64d1(v1,v2,v3,v4) (255 & ((v1 << 2) | (v2 >> 4))); +#define b64d2(v1,v2,v3,v4) (255 & ((v2 << 4) | (v3 >> 2))); +#define b64d3(v1,v2,v3,v4) (255 & ((v3 << 6) | v4)); + #endif /* SETUP_INI_H */ diff --git a/inilex.ll b/inilex.ll index 81a7f24..2e767ec 100644 --- a/inilex.ll +++ b/inilex.ll @@ -48,36 +48,58 @@ STR [!a-zA-Z0-9_./:\+~-]+ %% -[0123456789abcdef]{32,32} { +[0-9a-f]{32} { yylval = (char *) new unsigned char[16]; memset (yylval, 0, 16); - for (int i = 0; i < 32; ++i) + int i, j; + unsigned char v1, v2; + for (i = 0, j = 0; i < 32; i += 2, ++j) { - unsigned char val = (unsigned char) yytext[i]; - if (val > '9') - val = val - 'a' + 10; - else - val = val - '0'; - ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4); + v1 = hexnibble((unsigned char) yytext[i+0]); + v2 = hexnibble((unsigned char) yytext[i+1]); + ((unsigned char *) yylval) [j] = nibbled1(v1, v2); } return MD5; } -[0123456789abcdef]{128,128} { +[0-9a-f]{128} { yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH]; memset (yylval, 0, SHA512_DIGEST_LENGTH); - for (int i = 0; i < SHA512_BLOCK_LENGTH; ++i) + int i, j; + unsigned char v1, v2; + for (i = 0, j = 0; i < SHA512_BLOCK_LENGTH; i += 2, ++j) { - unsigned char val = (unsigned char) yytext[i]; - if (val > '9') - val = val - 'a' + 10; - else - val = val - '0'; - ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4); + v1 = hexnibble((unsigned char) yytext[i+0]); + v2 = hexnibble((unsigned char) yytext[i+1]); + ((unsigned char *) yylval) [j] = nibbled1(v1, v2); } return SHA512; } +[a-zA-Z0-9_-]{86} { + /* base64url as defined in RFC4648 */ + yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH]; + memset (yylval, 0, SHA512_DIGEST_LENGTH); + int i, j; + unsigned char v1, v2, v3, v4; + for (i = 0, j = 0; i < 4*(SHA512_DIGEST_LENGTH/3); i += 4, j += 3) + { + v1 = b64url(((unsigned char) yytext[i+0])); + v2 = b64url(((unsigned char) yytext[i+1])); + v3 = b64url(((unsigned char) yytext[i+2])); + v4 = b64url(((unsigned char) yytext[i+3])); + ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4); + ((unsigned char *) yylval) [j+1] = b64d2(v1, v2, v3, v4); + ((unsigned char *) yylval) [j+2] = b64d3(v1, v2, v3, v4); + } + v1 = b64url((unsigned char) yytext[i+0]); + v2 = b64url((unsigned char) yytext[i+1]); + v3 = 0; + v4 = 0; + ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4); + return SHA512B64URL; +} + \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1]; strcpy (yylval, yytext+1); yylval[strlen (yylval)-1] = 0; @@ -98,6 +120,7 @@ STR [!a-zA-Z0-9_./:\+~-]+ "Description:" BEGIN (descriptionstate); return DESCTAG; "Size:" return FILESIZE; "MD5sum:" return MD5LINE; +"SHA512:" return SHA512LINE; "Installed-Size:" return INSTALLEDSIZE; "Maintainer:" BEGIN (eolstate); return MAINTAINER; "Architecture:" return ARCHITECTURE; diff --git a/iniparse.yy b/iniparse.yy index cab84f2..0cd1c64 100644 --- a/iniparse.yy +++ b/iniparse.yy @@ -42,8 +42,9 @@ void add_correct_version(); %token CATEGORY DEPENDS REQUIRES %token APATH PPATH INCLUDE_SETUP EXCLUDE_PACKAGE DOWNLOAD_URL %token T_PREV T_CURR T_TEST -%token SHA512 MD5 INSTALLEDSIZE MAINTAINER PRIORITY -%token DESCTAG DESCRIPTION FILESIZE ARCHITECTURE SOURCEPACKAGE MD5LINE +%token SHA512 SHA512B64URL MD5 INSTALLEDSIZE MAINTAINER PRIORITY +%token MD5LINE SHA512LINE +%token DESCTAG DESCRIPTION FILESIZE ARCHITECTURE SOURCEPACKAGE %token RECOMMENDS PREDEPENDS %token SUGGESTS CONFLICTS REPLACES PROVIDES PACKAGENAME STRTOEOL PARAGRAPH %token EMAIL COMMA OR NL AT @@ -107,6 +108,8 @@ singleitem /* non-empty */ | DIRECTORY STRING NL { /* TODO */ } | STANDARDSVERSION STRING NL { /* TODO */ } | MD5LINE MD5 NL { iniBuilder->buildInstallMD5 ((unsigned char *)$2); } + | MD5LINE SHA512 NL { iniBuilder->buildInstallSHA512 ((unsigned char *)$2); } + | MD5LINE SHA512B64URL NL { iniBuilder->buildInstallSHA512 ((unsigned char *)$2); } | SOURCEPACKAGE source NL | CATEGORY categories NL | INSTALL STRING { iniBuilder->buildPackageInstall ($2); } installmeta NL @@ -146,11 +149,13 @@ installmeta: /* empty */ installchksum: /* empty */ | MD5 { iniBuilder->buildInstallMD5 ((unsigned char *)$1);} | SHA512 { iniBuilder->buildInstallSHA512 ((unsigned char *)$1);} + | SHA512B64URL { iniBuilder->buildInstallSHA512 ((unsigned char *)$1);} ; sourcechksum: /* empty */ | MD5 { iniBuilder->buildSourceMD5 ((unsigned char *)$1); } | SHA512 { iniBuilder->buildSourceSHA512 ((unsigned char *)$1); } + | SHA512B64URL { iniBuilder->buildSourceSHA512 ((unsigned char *)$1); } ; source /* non-empty */