diff --git a/go.mod b/go.mod index 1f596cd36b..91caa6e6a5 100644 --- a/go.mod +++ b/go.mod @@ -185,7 +185,7 @@ replace ( cloud.google.com/go/compute/metadata => cloud.google.com/go/compute/metadata v0.1.0 github.com/labstack/echo/v4 => github.com/labstack/echo/v4 v4.6.1 github.com/pingcap/log => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 - github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240305095250-688ad439ef31 + github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240704052347-b6199b7bccae github.com/swaggo/swag => github.com/swaggo/swag v1.6.7 google.golang.org/grpc => google.golang.org/grpc v1.29.0 ) diff --git a/go.sum b/go.sum index 075d6141a3..2e50aa5875 100644 --- a/go.sum +++ b/go.sum @@ -795,8 +795,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/sjjian/parser v0.0.0-20240305095250-688ad439ef31 h1:E3JSX1FjUlg8ep8XQlLkdTFbZhM4tmecpdfZhUuubLs= -github.com/sjjian/parser v0.0.0-20240305095250-688ad439ef31/go.mod h1:Qq2tnreUXwVo7NAKAHmbWFsgqpDUkxwhJCClY+ZCudA= +github.com/sjjian/parser v0.0.0-20240704052347-b6199b7bccae h1:rTwogc7Uq0/7zMHNhpQTqjtGKdccVh8Z8vHReIlsXG0= +github.com/sjjian/parser v0.0.0-20240704052347-b6199b7bccae/go.mod h1:Qq2tnreUXwVo7NAKAHmbWFsgqpDUkxwhJCClY+ZCudA= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= diff --git a/sqle/driver/mysql/splitter/block.go b/sqle/driver/mysql/splitter/block.go new file mode 100644 index 0000000000..8e4881c556 --- /dev/null +++ b/sqle/driver/mysql/splitter/block.go @@ -0,0 +1,80 @@ +package splitter + +import ( + "github.com/pingcap/parser" + "strings" +) + +type Block interface { + MatchBegin(token *parser.Token) bool + MatchEnd(token *parser.Token) bool +} + +var allBlocks []Block = []Block{ + BeginEndBlock{}, + IfEndIfBlock{}, + CaseEndCaseBlock{}, + RepeatEndRepeatBlock{}, + WhileEndWhileBlock{}, + LoopEndLoopBlock{}, +} + +type LoopEndLoopBlock struct{} + +func (b BeginEndBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.Begin +} + +func (b BeginEndBlock) MatchEnd(token *parser.Token) bool { + return true +} + +type IfEndIfBlock struct{} + +func (b IfEndIfBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.IfKwd +} + +func (b IfEndIfBlock) MatchEnd(token *parser.Token) bool { + return token.TokenType() == parser.IfKwd +} + +type CaseEndCaseBlock struct{} + +func (b CaseEndCaseBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.CaseKwd +} + +func (b CaseEndCaseBlock) MatchEnd(token *parser.Token) bool { + return token.TokenType() == parser.CaseKwd +} + +type RepeatEndRepeatBlock struct{} + +func (b RepeatEndRepeatBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.Repeat +} + +func (b RepeatEndRepeatBlock) MatchEnd(token *parser.Token) bool { + return token.TokenType() == parser.Repeat +} + +type WhileEndWhileBlock struct{} + +func (b WhileEndWhileBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.Identifier && strings.ToUpper(token.Ident()) == "WHILE" +} + +func (b WhileEndWhileBlock) MatchEnd(token *parser.Token) bool { + return token.TokenType() == parser.Identifier && strings.ToUpper(token.Ident()) == "WHILE" +} + +type BeginEndBlock struct{} + +func (b LoopEndLoopBlock) MatchBegin(token *parser.Token) bool { + return token.TokenType() == parser.Identifier && strings.ToUpper(token.Ident()) == "LOOP" +} + +func (b LoopEndLoopBlock) MatchEnd(token *parser.Token) bool { + return token.TokenType() == parser.Identifier && strings.ToUpper(token.Ident()) == "LOOP" +} diff --git a/sqle/driver/mysql/splitter/delimiter.go b/sqle/driver/mysql/splitter/delimiter.go new file mode 100644 index 0000000000..f264837bf7 --- /dev/null +++ b/sqle/driver/mysql/splitter/delimiter.go @@ -0,0 +1,150 @@ +package splitter + +import ( + "errors" + "github.com/pingcap/parser" + "strings" +) + +const ( + BackSlash int = '\\' + BackSlashString string = "\\" + BlankSpace string = " " + DefaultDelimiterString string = ";" + DelimiterCommand string = "DELIMITER" + DelimiterCommandSort string = `\d` +) + +type Delimiter struct { + FirstTokenTypeOfDelimiter int + FirstTokenValueOfDelimiter string + DelimiterStr string + line int + startPos int +} + +func NewDelimiter() *Delimiter { + return &Delimiter{} +} + +/* + 根据传入的SQL和位置,判断当前位置开始是否是一个缩写分隔符的语法 + +判断依据:从当前位置开始是否紧跟着一个\\d +不使用Lex的原因: + 1. \\d会被识别为三个token,即: \ \ d + 2. Lex可能会跳过空格和注释,因此这里使用字符串匹配 +*/ +func (d *Delimiter) isSortDelimiterCommand(sql string, index int) bool { + return index+2 < len(sql) && sql[index:index+2] == "\\d" +} + +// DELIMITER会被识别为identifier,因此这里仅需识别其值是否相等 +func (d *Delimiter) isDelimiterCommand(token string) bool { + return strings.ToUpper(token) == DelimiterCommand +} + +// 获取下一个参数及其参数的结束位置 +// 该函数翻译自MySQL Client获取delimiter值的代码,参考:https://github.com/mysql/mysql-server/blob/824e2b4064053f7daf17d7f3f84b7a3ed92e5fb4/client/mysql.cc#L4866 +func getDelimiterValueAndEndPos(sqlAfterDelimiter string) (string, int) { + ptr := 0 + start := 0 + quoted := false + qType := byte(0) + + // 跳过开头的空格 + for ptr < len(sqlAfterDelimiter) && isWhitespace(sqlAfterDelimiter[ptr]) { + ptr++ + } + + if ptr == len(sqlAfterDelimiter) { + return "", -1 + } + + // 检查是否为引号字符串 + if sqlAfterDelimiter[ptr] == '\'' || sqlAfterDelimiter[ptr] == '"' || sqlAfterDelimiter[ptr] == '`' { + qType = sqlAfterDelimiter[ptr] + quoted = true + ptr++ + } + + start = ptr + + // 找到字符串结尾 + for ptr < len(sqlAfterDelimiter) { + if !quoted && sqlAfterDelimiter[ptr] == '\\' && ptr+1 < len(sqlAfterDelimiter) { // 跳过转义字符 + ptr += 2 + } else if (!quoted && isWhitespace(sqlAfterDelimiter[ptr])) || (quoted && sqlAfterDelimiter[ptr] == qType) { + break + } else { + ptr++ + } + } + // 结束位置为分隔符后一位 + var endPos int = ptr + if ptr < len(sqlAfterDelimiter) { + endPos++ + } + return sqlAfterDelimiter[start:ptr], endPos +} + +// 辅助函数,判断字符是否为空格 +func isWhitespace(c byte) bool { + return c == ' ' || c == '\t' || c == '\n' || c == '\r' +} + +var ErrDelimiterCanNotExtractToken = errors.New("sorry, we cannot extract any token form the delimiter you provide, please change a delimiter") +var ErrDelimiterContainsBackslash = errors.New("DELIMITER cannot contain a backslash character") +var ErrDelimiterContainsBlankSpace = errors.New("DELIMITER should not contain blank space") +var ErrDelimiterMissing = errors.New("DELIMITER must be followed by a 'delimiter' character or string") +var ErrDelimiterReservedKeyword = errors.New("delimiter should not use a reserved keyword") + +/* +该方法设置分隔符,对分隔符的内容有一定的限制: + + 1. 不允许分隔符内部包含反斜杠 + 2. 不允许分隔符为空字符串 + 3. 不允许分隔符为mysql的保留字,因为这样会被scanner扫描为其他类型的token,从而绕过判断分隔符的逻辑 + +注:其中1和2与MySQL客户端对分隔符内容一致,错误内容参考MySQL客户端源码中的com_delimiter函数 +https://github.com/mysql/mysql-server/blob/824e2b4064053f7daf17d7f3f84b7a3ed92e5fb4/client/mysql.cc#L4621 +*/ +func (d *Delimiter) setDelimiter(delimiter string) (err error) { + if delimiter == "" { + return ErrDelimiterMissing + } + if strings.Contains(delimiter, BackSlashString) { + return ErrDelimiterContainsBackslash + } + if strings.Contains(delimiter, BlankSpace) { + return ErrDelimiterContainsBlankSpace + } + if isReservedKeyWord(delimiter) { + return ErrDelimiterReservedKeyword + } + token := parser.NewScanner(delimiter).NextToken() + d.FirstTokenTypeOfDelimiter = token.TokenType() + if d.FirstTokenTypeOfDelimiter == 0 { + return ErrDelimiterCanNotExtractToken + } + d.FirstTokenValueOfDelimiter = token.Ident() + d.DelimiterStr = delimiter + return nil +} + +func isReservedKeyWord(input string) bool { + token := parser.NewScanner(input).NextToken() + tokenType := token.TokenType() + if len(token.Ident()) < len(input) { + // 如果分隔符无法识别为一个token,则一定不是关键字 + return false + } + // 如果分隔符识别为一个关键字,但不知道是哪个关键字,则为identifier,此时就非保留字 + return tokenType != parser.Identifier && tokenType > parser.YyEOFCode && tokenType < parser.YyDefault +} + +func (d *Delimiter) reset() error { + d.line = 0 + d.startPos = 0 + return d.setDelimiter(DefaultDelimiterString) +} diff --git a/sqle/driver/mysql/splitter/splitter.go b/sqle/driver/mysql/splitter/splitter.go new file mode 100644 index 0000000000..9892bf4d19 --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter.go @@ -0,0 +1,284 @@ +package splitter + +import ( + "bytes" + + "strings" + + "github.com/pingcap/parser" + "github.com/pingcap/parser/ast" +) + +type splitter struct { + parser *parser.Parser + delimiter *Delimiter + scanner *parser.Scanner +} + +func NewSplitter() *splitter { + return &splitter{ + parser: parser.New(), + delimiter: NewDelimiter(), + scanner: parser.NewScanner(""), + } +} + +func (s *splitter) ParseSqlText(sqlText string) ([]ast.StmtNode, error) { + err := s.delimiter.reset() + if err != nil { + return nil, err + } + results, err := s.splitSqlText(sqlText) + if err != nil { + return nil, err + } + return s.processToExecutableNodes(results) +} + +func (s *splitter) processToExecutableNodes(results []*singleSQL) ([]ast.StmtNode, error) { + var executableNodes []ast.StmtNode + for _, result := range results { + // 根据解析结果生成得到sql的抽象语法树 + stmt, err := s.parser.ParseOneStmt(result.originSql, "", "") + if err != nil { + // 若解析结果为错误,则将分割后的SQL作为不可解析的SQL添加到executableNodes中 + unParsedStmt := &ast.UnparsedStmt{} + unParsedStmt.SetStartLine(result.lineNumber) + unParsedStmt.SetText(result.originSql) + executableNodes = append(executableNodes, unParsedStmt) + } else { + // 若能成功解析,则将解析的结果添加到executableNodes中 + stmt.SetStartLine(result.lineNumber) + executableNodes = append(executableNodes, stmt) + } + } + return executableNodes, nil +} + +type singleSQL struct { + originSql string + lineNumber int + isDelimiterCommand bool +} + +func (s singleSQL) IsEmpty() bool { + return s.originSql == "" +} + +func (s *splitter) splitSqlText(sqlText string) (results []*singleSQL, err error) { + result, err := s.getNextSql(sqlText) + if err != nil { + return nil, err + } + if !result.IsEmpty() && !result.isDelimiterCommand { + results = append(results, result) + } + // 递归切分剩余SQL + if s.scanner.Offset() < len(sqlText) { + subResults, err := s.splitSqlText(sqlText[s.scanner.Offset():]) + if err != nil { + return results, err + } + results = append(results, subResults...) + } + return results, nil +} + +func (s *splitter) getNextSql(sqlText string) (*singleSQL, error) { + matchedDelimiterCommand, err := s.matchAndSetCustomDelimiter(sqlText) + if err != nil { + return nil, err + } + // 根据分隔符匹配到SQL结尾,输出切分后的原始SQL + if matchedDelimiterCommand || s.matchSql(sqlText) { + buff := bytes.Buffer{} + buff.WriteString(sqlText[:s.scanner.Offset()]) + lineBeforeStart := strings.Count(sqlText[:s.delimiter.startPos], "\n") + originSql := s.formateOriginSql(strings.TrimSpace(buff.String())) + if originSql == "" { + // 跳过空SQL + return &singleSQL{}, nil + } + result := &singleSQL{ + originSql: originSql, + lineNumber: s.delimiter.line + lineBeforeStart + 1, + isDelimiterCommand: matchedDelimiterCommand, + } + s.delimiter.line += s.scanner.ScannedLines() // pos().Line-1表示的是该SQL中有多少换行 + return result, nil + } + // 处理剩余SQL文本 + restOfSql := s.formateOriginSql(strings.TrimSpace(sqlText)) + if restOfSql == "" { + // 跳过空SQL + return &singleSQL{}, nil + } + + return &singleSQL{ + originSql: restOfSql, + lineNumber: s.delimiter.line + strings.Count(sqlText[:s.delimiter.startPos], "\n") + 1, + isDelimiterCommand: matchedDelimiterCommand, + }, nil +} + +// 如果SQL有分隔符,则保留SQL的分隔符, +// 如果SQL没有分隔符,则返回没有分隔符的SQL +// 如果分隔符不是默认分隔符,则将其替换为默认分隔符 +// 如果去除分隔符和空白符之后SQL为空字符串,则返回空字符串,空字符串需跳过 +func (s *splitter) formateOriginSql(originSql string) string { + if strings.HasSuffix(originSql, s.delimiter.DelimiterStr) { + trimmedSql := strings.TrimSuffix(originSql, s.delimiter.DelimiterStr) + if trimmedSql == "" { + return "" + } + if s.delimiter.DelimiterStr != DefaultDelimiterString { + originSql = trimmedSql + DefaultDelimiterString + } + } + return originSql +} + +func (s *splitter) matchSql(sql string) bool { + s.scanner.Reset(sql) + token := &parser.Token{} + var isFirstToken bool = true + + for s.scanner.Offset() < len(sql) { + token = s.scanner.NextToken() + if isFirstToken { + s.delimiter.startPos = s.scanner.Offset() + isFirstToken = false + } + token = s.skipBeginEndBlock(token) + if s.isTokenMatchDelimiter(token) { + return true + } + } + return false +} + +func (s *splitter) skipBeginEndBlock(token *parser.Token) *parser.Token { + var blockStack []Block + if token.TokenType() == parser.Begin { + blockStack = append(blockStack, BeginEndBlock{}) + } + for len(blockStack) > 0 { + token = s.scanner.NextToken() + for _, block := range allBlocks { + if block.MatchBegin(token) { + blockStack = append(blockStack, block) + break + } + } + /* + begin...end语句块示例如下,语法都以END+对应开始标志为该语句块的结束,因此当匹配到END时,判断下一个TOKEN是否匹配该语句块,若匹配则弹出该语句块 + BEGIN + IF + END IF + WHILE + END WHILE + END + */ + if token.TokenType() == parser.End { + // 如果匹配到END,则需要判断END后的token是否匹配当前的Block + currentBlock := blockStack[len(blockStack)-1] + token = s.scanner.NextToken() + if currentBlock.MatchEnd(token) { + blockStack = blockStack[:len(blockStack)-1] + } + // 如果未匹配到,则为错误的begin...end语句块 + } + if len(blockStack) == 0 { + // 语句块栈全部弹出,则begin...end语句块正确匹配,返回结束循环,返回END后一个TOKEN + break + } + // 如果匹配到SQL的结尾都没有结束该begin...end语句块,返回最后一个TOKEN + if len(s.scanner.Text()) == s.scanner.Offset() { + break + } + } + return token +} + +// ref:https://dev.mysql.com/doc/refman/8.4/en/flow-control-statements.html +func (s *splitter) isTokenMatchDelimiter(token *parser.Token) bool { + switch token.TokenType() { + case s.delimiter.FirstTokenTypeOfDelimiter: + /* + 在mysql client的语法中需要跳过注释以及分隔符处于引号中的情况,由于scanner.Lex会自动跳过注释,因此,仅需要判断分隔符处于引号中的情况。对于该方法,以分隔符的第一个token作为特征仅需匹配,可能会匹配到由引号括起的情况,存在stringLit和identifier两种token需要进一步判断: + 1. 当匹配到identifier时,identifier有可能由反引号括起: + 1. 若identifier没有反引号括起,则不需要判断是否跳过 + 2. 若identifier被反引号括起,匹配的字符串会带上反引号,能在匹配字符串时能够检查出是否需要跳过 + 2. 当匹配到stringLit时,stringLit一定是由单引号或双引号括起: + 1. 当分隔符第一个token值与stringLit的token值不等,那么一定不是分隔符,则跳过 + 2. 当分隔符第一个token值与stringLit的token值相等, 如:"'abc'd" '"abc"d'会因为字符串不匹配而跳过 + */ + // 1. 当分隔符第一个token值与stringLit的token值不等,那么一定不是分隔符,则跳过 + if token.TokenType() == parser.StringLit && token.Ident() != s.delimiter.FirstTokenValueOfDelimiter { + return false + } + // 2. 定位特征的第一个字符所处的位置 + indexInToken := strings.Index(token.Ident(), s.delimiter.FirstTokenValueOfDelimiter) + if indexInToken == -1 { + return false + } + // 3. 字符串匹配 + begin := s.scanner.Offset() + indexInToken + end := begin + len(s.delimiter.DelimiterStr) + if begin < 0 || end > len(s.scanner.Text()) { + return false + } + expected := s.scanner.Text()[begin:end] + if expected != s.delimiter.DelimiterStr { + return false + } + s.scanner.SetCursor(end) + return true + + case parser.Invalid: + s.scanner.HandleInvalid() + } + return false +} + +/* +该方法检测sql文本开头是否是自定义分隔符语法,若是匹配并更新分隔符: + + 1. 分隔符语法满足:delimiter str 或者 \d str + 2. 参考链接:https://dev.mysql.com/doc/refman/5.7/en/mysql-commands.html +*/ +func (s *splitter) matchAndSetCustomDelimiter(sql string) (bool, error) { + // 重置扫描器 + s.scanner.Reset(sql) + var sqlAfterDelimiter string + // 根据token的类型判断是否是分隔符语法的开始 + token := s.scanner.NextToken() + switch token.TokenType() { + case BackSlash: + if s.delimiter.isSortDelimiterCommand(sql, s.scanner.Offset()) { + sqlAfterDelimiter = sql[s.scanner.Offset()+2:] // \d的长度是2字节 + s.delimiter.startPos = s.scanner.Offset() + s.scanner.SetCursor(s.scanner.Offset() + 2) + } + case parser.Identifier: + if s.delimiter.isDelimiterCommand(token.Ident()) { + sqlAfterDelimiter = sql[s.scanner.Offset()+9:] //DELIMITER的长度是9字节 + s.delimiter.startPos = s.scanner.Offset() + s.scanner.SetCursor(s.scanner.Offset() + 9) + } + default: + return false, nil + } + // 若定义分隔符命令后仍有文本,则需要获取和设置自定义分隔符的值,并重置游标 + if sqlAfterDelimiter != "" { + // 获取分隔符定义语法后的自定义分隔符,并设置自定义分隔符 + newDelimiterValue, endPos := getDelimiterValueAndEndPos(sqlAfterDelimiter) + if err := s.delimiter.setDelimiter(newDelimiterValue); err != nil { + return false, err + } + // 重置游标到分隔符语法后 + s.scanner.SetCursor(s.scanner.Offset() + endPos) + return true, nil + } + return false, nil +} diff --git a/sqle/driver/mysql/splitter/splitter_test.go b/sqle/driver/mysql/splitter/splitter_test.go new file mode 100644 index 0000000000..01a3fb998a --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter_test.go @@ -0,0 +1,1186 @@ +package splitter + +import ( + "bytes" + "fmt" + "github.com/pingcap/parser/ast" + parser_formate "github.com/pingcap/parser/format" + _ "github.com/pingcap/tidb/types/parser_driver" + "github.com/stretchr/testify/assert" + "os" + "strings" + "testing" +) + +func TestSplitSqlText(t *testing.T) { + s := NewSplitter() + // 读取文件内容 + testCases := []struct { + filePath string + expectedLength int + }{ + {"splitter_test_1.sql", 14}, + {"splitter_test_2.sql", 14}, + {"splitter_test_3.sql", 4}, + {"splitter_test_skip_quoted_delimiter.sql", 18}, + } + for _, testCase := range testCases { + t.Run(testCase.filePath, func(t *testing.T) { + sqls, err := os.ReadFile(testCase.filePath) + if err != nil { + t.Fatalf("failed to read file: %v", err) + } + splitResults, err := s.splitSqlText(string(sqls)) + if err != nil { + t.Fatalf(err.Error()) + } + assert.Equal(t, testCase.expectedLength, len(splitResults)) + }) + } +} + +func TestSplitterProcess(t *testing.T) { + s := NewSplitter() + testCases := []struct { + filePath string + expectedLength int + }{ + {"splitter_test_1.sql", 14}, + {"splitter_test_2.sql", 14}, + {"splitter_test_3.sql", 4}, + {"splitter_test_skip_quoted_delimiter.sql", 18}, + } + for _, testCase := range testCases { + t.Run(testCase.filePath, func(t *testing.T) { + // 读取文件内容 + sqlText, err := os.ReadFile(testCase.filePath) + if err != nil { + t.Fatalf("无法读取文件: %v", err) + } + executableNodes, err := s.ParseSqlText(string(sqlText)) + if err != nil { + t.Fatalf(err.Error()) + } + assert.Equal(t, testCase.expectedLength, len(executableNodes)) + }) + } +} + +func TestIsDelimiterReservedKeyWord(t *testing.T) { + tests := []struct { + delimiter string + expected bool + }{ + // 非关键字 + {"id", false}, + {"$$", false}, + {";;", false}, + {"\\", false}, + {"Abscsd", false}, + {"%%", false}, + {"|", false}, + {"%", false}, + {"foo", false}, + {"column1", false}, + {"table_name", false}, + {"_underscore", false}, + // 关键字 + {"&&", true}, + {"=", true}, + {"!=", true}, + {"<=", true}, + {">=", true}, + {"||", true}, + {"<>", true}, + {"IN", true}, + {"AS", true}, + {"Update", true}, + {"Delete", true}, + {"not", true}, + {"Order", true}, + {"by", true}, + {"Select", true}, + {"From", true}, + {"Where", true}, + {"Join", true}, + {"Inner", true}, + {"Left", true}, + {"Right", true}, + {"Full", true}, + {"Group", true}, + {"Having", true}, + {"Insert", true}, + {"Into", true}, + {"Values", true}, + {"Create", true}, + {"Table", true}, + {"Alter", true}, + {"Drop", true}, + {"Truncate", true}, + {"Union", true}, + {"Exists", true}, + {"Like", true}, + {"Distinct", true}, + {"And", true}, + {"Or", true}, + {"Limit", true}, + {"ALL", true}, + {"ANY", true}, + {"BETWEEN", true}, + } + + for _, test := range tests { + t.Run(test.delimiter, func(t *testing.T) { + result := isReservedKeyWord(test.delimiter) + if result != test.expected { + t.Errorf("isDelimiterReservedKeyWord(%s) = %v; want %v", test.delimiter, result, test.expected) + } + }) + } +} + +func TestSkipQuotedDelimiter(t *testing.T) { + s := NewSplitter() + // 读取文件内容 + sqls, err := os.ReadFile("splitter_test_skip_quoted_delimiter.sql") + if err != nil { + t.Fatalf("无法读取文件: %v", err) + } + splitResults, err := s.splitSqlText(string(sqls)) + if err != nil { + t.Fatalf(err.Error()) + } + for _, result := range splitResults { + fmt.Print("------------------------------\n") + fmt.Printf("SQL语句在第%v行\n", result.lineNumber) + fmt.Printf("SQL语句为:\n%v\n", result.originSql) + } + if len(splitResults) != 18 { + t.FailNow() + } +} + +func TestStartLine(t *testing.T) { + // 测试用例第2个到第5个sql是解析器不能解析的sql + p := NewSplitter() + stmts, err := p.ParseSqlText(`grant all on point_trans_shard_00_part_202401 to kgoldpointapp; +create table point_trans_shard_00_part_202401(like point_trans_shard_00 including all) inherits(point_trans_shard_00); +Alter table point_trans_shard_00_part_202401 ADD CONSTRAINT chk_point_trans_shard_202401 CHECK (processedtime >= '1704038400000'::bigint AND processedtime < '1706716800000'::bigint ); +create table point_trans_source_shard_00_part_202401(like point_trans_source_shard_00 including all) inherits(point_trans_source_shard_00); +Alter table point_trans_source_shard_00_part_202401 ADD CONSTRAINT chk_point_trans_source_shard_202401 CHECK (processedtime >= '1704038400000'::bigint AND processedtime < '1706716800000'::bigint ); +grant select on point_trans_shard_00_part_202401 to prd_fin, dbsec, sec_db_scan; +grant all on point_trans_source_shard_00_part_202401 to kgoldpointapp; +grant select on point_trans_source_shard_00_part_202401 to prd_fin, dbsec, sec_db_scan; +`) + if err != nil { + t.Error(err) + return + } + if len(stmts) != 8 { + t.Errorf("expect 2 stmts, actual is %d", len(stmts)) + return + } + for i, stmt := range stmts { + if stmt.StartLine() != i+1 { + t.Errorf("expect start line is %d, actual is %d", i+1, stmt.StartLine()) + } + } + + // 所有测试用例都是可以解析的sql + stmts, err = p.ParseSqlText(`grant select on point_trans_shard_00_part_202401 to prd_fin, dbsec, sec_db_scan; +grant all on point_trans_source_shard_00_part_202401 to kgoldpointapp; +grant select on point_trans_source_shard_00_part_202401 to prd_fin, dbsec, sec_db_scan; +`) + if err != nil { + t.Error(err) + return + } + if len(stmts) != 3 { + t.Errorf("expect 3 nodes, actual is %d", len(stmts)) + return + } + for i, node := range stmts { + if node.StartLine() != i+1 { + t.Errorf("expect start line is %d, actual is %d", i+1, node.StartLine()) + } + } + + // 所有测试用例都是不可以解析的sql + stmts, err = p.ParseSqlText(`create table point_trans_shard_00_part_202401(like point_trans_shard_00 including all) inherits(point_trans_shard_00); +Alter table point_trans_shard_00_part_202401 ADD CONSTRAINT chk_point_trans_shard_202401 CHECK (processedtime >= '1704038400000'::bigint AND processedtime < '1706716800000'::bigint ); +create table point_trans_source_shard_00_part_202401(like point_trans_source_shard_00 including all) inherits(point_trans_source_shard_00);`) + if err != nil { + t.Error(err) + return + } + if len(stmts) != 3 { + t.Errorf("expect 3 stmts, actual is %d", len(stmts)) + return + } + for i, stmt := range stmts { + if stmt.StartLine() != i+1 { + t.Errorf("expect start line is %d, actual is %d", i+1, stmt.StartLine()) + } + } + + // 并排sql测试用例,备注:3个sql都不能被解析 + stmts, err = p.ParseSqlText(`create table point_trans_shard_00_part_202401(like point_trans_shard_00 including all) inherits(point_trans_shard_00); +Alter table point_trans_shard_00_part_202401 ADD CONSTRAINT chk_point_trans_shard_202401 CHECK (processedtime >= '1704038400000'::bigint AND processedtime < '1706716800000'::bigint );create table point_trans_source_shard_00_part_202401(like point_trans_source_shard_00 including all) inherits(point_trans_source_shard_00);`) + if err != nil { + t.Error(err) + return + } + if len(stmts) != 3 { + t.Errorf("expect 3 stmts, actual is %d", len(stmts)) + return + } + + for i, stmt := range stmts { + if i == 2 { + if stmt.StartLine() != 2 { + t.Errorf("expect start line is 2, actual is %d", stmt.StartLine()) + } + } else { + if stmt.StartLine() != i+1 { + t.Errorf("expect start line is %d, actual is %d", i+1, stmt.StartLine()) + } + } + } +} + +func TestPerfectParse(t *testing.T) { + parser := NewSplitter() + + stmt, err := parser.ParseSqlText("OPTIMIZE TABLE foo;") + if err != nil { + t.Error(err) + return + } + if _, ok := stmt[0].(*ast.UnparsedStmt); !ok { + t.Errorf("expect stmt type is unparsedStmt, actual is %T", stmt) + return + } + + type testCase struct { + sql string + expect []string + } + + tc := []testCase{ + { + sql: `SELECT * FROM db1.t1`, + expect: []string{ + `SELECT * FROM db1.t1`, + }, + }, + { + sql: `SELECT * FROM db1.t1;SELECT * FROM db2.t2`, + expect: []string{ + "SELECT * FROM db1.t1", + "SELECT * FROM db2.t2", + }, + }, + { + sql: "SELECT * FROM db1.t1;OPTIMIZE TABLE foo;SELECT * FROM db2.t2", + expect: []string{ + "SELECT * FROM db1.t1;", + "OPTIMIZE TABLE foo;", + "SELECT * FROM db2.t2", + }, + }, + { + sql: "OPTIMIZE TABLE foo;SELECT * FROM db1.t1;SELECT * FROM db2.t2", + expect: []string{ + "OPTIMIZE TABLE foo;", + "SELECT * FROM db1.t1;", + "SELECT * FROM db2.t2", + }, + }, + { + sql: "SELECT * FROM db1.t1;SELECT * FROM db2.t2;OPTIMIZE TABLE foo", + expect: []string{ + "SELECT * FROM db1.t1;", + "SELECT * FROM db2.t2;", + "OPTIMIZE TABLE foo", + }, + }, + { + sql: "SELECT FROM db2.t2 where a=\"asd;\"; SELECT * FROM db1.t1;", + expect: []string{ + "SELECT FROM db2.t2 where a=\"asd;\";", + " SELECT * FROM db1.t1;", + }, + }, + { + sql: "SELECT * FROM db1.t1;OPTIMIZE TABLE foo;OPTIMIZE TABLE foo;SELECT * FROM db2.t2", + expect: []string{ + "SELECT * FROM db1.t1;", + "OPTIMIZE TABLE foo;", + "OPTIMIZE TABLE foo;", + "SELECT * FROM db2.t2", + }, + }, + { + sql: "OPTIMIZE TABLE foo;SELECT * FROM db1.t1;OPTIMIZE TABLE foo;SELECT * FROM db2.t2", + expect: []string{ + "OPTIMIZE TABLE foo;", + "SELECT * FROM db1.t1;", + "OPTIMIZE TABLE foo;", + "SELECT * FROM db2.t2", + }, + }, + { + sql: "SELECT * FROM db1.t1;OPTIMIZE TABLE foo;SELECT * FROM db2.t2;OPTIMIZE TABLE foo", + expect: []string{ + "SELECT * FROM db1.t1;", + "OPTIMIZE TABLE foo;", + "SELECT * FROM db2.t2;", + "OPTIMIZE TABLE foo", + }, + }, + { + sql: ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +END; +`, + expect: []string{ + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +END;`, + }, + }, + { + sql: ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +SELECT COUNT(*) FROM user; +END; +`, + expect: []string{ + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +SELECT COUNT(*) FROM user; +END;`, + }, + }, + { + sql: ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +SELECT COUNT(*) FROM user; +SELECT COUNT(*) FROM user; +END; +`, + expect: []string{ + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +SELECT COUNT(*) FROM user; +SELECT COUNT(*) FROM user; +END;`, + }, + }, + { + sql: ` +SELECT * FROM db1.t1; +CREATE PROCEDURE proc1(OUT s int) +BEGIN +END; +`, + expect: []string{ + `SELECT * FROM db1.t1;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN +END;`, + }, + }, + { + sql: ` +SELECT * FROM db1.t1; +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +`, + expect: []string{ + `SELECT * FROM db1.t1;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + }, + }, + { + sql: ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +SELECT * FROM db1.t1; +`, + expect: []string{ + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + `SELECT * FROM db1.t1;`, + }, + }, + { + sql: ` +SELECT * FROM db1.t1; +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +SELECT * FROM db1.t1; +`, + expect: []string{ + `SELECT * FROM db1.t1;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + `SELECT * FROM db1.t1;`, + }, + }, + { + sql: ` +SELECT * FROM db1.t1; +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +SELECT * FROM db1.t1; +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END; +SELECT * FROM db1.t1; +`, + expect: []string{ + `SELECT * FROM db1.t1;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + `SELECT * FROM db1.t1;`, + ` +CREATE PROCEDURE proc1(OUT s int) +BEGIN + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; + SELECT COUNT(*) FROM user; +END;`, + `SELECT * FROM db1.t1;`, + }, + }, + { // 匹配特殊字符结束 + sql: "select * from �E", + expect: []string{ + `select * from �E`, + }, + }, + { // 匹配特殊字符后是; + sql: "select * from �E;select * from t1", + expect: []string{ + `select * from �E;`, + "select * from t1", + }, + }, + { // 匹配特殊字符在中间 + sql: "select * from �E where id = 1;select * from �E ", + expect: []string{ + `select * from �E where id = 1;`, + `select * from �E `, + }, + }, + { // 匹配特殊字符在开头 + sql: " where id = 1;select * from �E ", + expect: []string{ + ` where id = 1;`, + `select * from �E `, + }, + }, + { // 匹配特殊字符在SQL开头 + sql: "select * from �E ; where id = 1", + expect: []string{ + `select * from �E ;`, + ` where id = 1`, + }, + }, + { // 匹配其他invalid场景 + sql: "@`", + expect: []string{ + "@`", + }, + }, + { // 匹配其他invalid场景 + sql: "@` ;select * from t1", + expect: []string{ + "@` ;select * from t1", + }, + }, + } + for _, c := range tc { + stmt, err := parser.splitSqlText(c.sql) + if err != nil { + t.Error(err) + return + } + if len(c.expect) != len(stmt) { + t.Errorf("expect sql length is %d, actual is %d, sql is [%s]", len(c.expect), len(stmt), c.sql) + } else { + for i, s := range stmt { + // 之前的测试用例预期对SQL的切分会保留SQL语句的前后的空格 + // 现在的切分会将SQL前后的空格去掉 + // 这里统一修改为匹配SQL语句,除去分隔符后的内容是否相等 + if strings.TrimSuffix(s.originSql, ";") != strings.TrimSuffix(strings.TrimSpace(c.expect[i]), ";") { + t.Errorf("expect sql is [%s], actual is [%s]", c.expect[i], s.originSql) + } + } + } + } +} + +func TestCharset(t *testing.T) { + parser := NewSplitter() + type testCase struct { + sql string + formatSQL string + noError bool + errMsg string + } + + tc := []testCase{ + { + sql: `create table t1(id int, name varchar(255) CHARACTER SET armscii8)`, + formatSQL: `CREATE TABLE t1 (id INT,name VARCHAR(255) CHARACTER SET ARMSCII8)`, + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255) CHARACTER SET armscii8 COLLATE armscii8_general_ci)`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255) CHARACTER SET ARMSCII8 COLLATE armscii8_general_ci)", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET armscii8`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = ARMSCII8", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET armscii8 COLLATE greek_general_ci`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = ARMSCII8 DEFAULT COLLATE = GREEK_GENERAL_CI", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET utf8mb3`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = UTF8", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_bin`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = UTF8_BIN", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET utf8 COLLATE utf8mb3_bin`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = UTF8_BIN", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255) CHARACTER SET utf8mb3)`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255) CHARACTER SET UTF8)", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255) CHARACTER SET utf8mb3 COLLATE cp852_general_ci)`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255) CHARACTER SET UTF8 COLLATE cp852_general_ci)", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255))default character set utf8mb3 COLLATE utf8mb3_unicode_ci;`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = UTF8_UNICODE_CI", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255))default character set utf8mb3 COLLATE big5_chinese_ci;`, + formatSQL: "CREATE TABLE t1 (id INT,name VARCHAR(255)) DEFAULT CHARACTER SET = UTF8 DEFAULT COLLATE = BIG5_CHINESE_CI", + noError: true, + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET aaa`, + noError: false, + errMsg: "[parser:1115]Unknown character set: 'aaa'", + }, + { + sql: `create table t1(id int, name varchar(255)) DEFAULT CHARACTER SET utf8mb3 COLLATE bbb`, + noError: false, + errMsg: "[ddl:1273]Unknown collation: 'bbb'", + }, + + // 原生测试用例,预期从报错调整为不报错。 + { + sql: `create table t (a longtext unicode);`, + formatSQL: "CREATE TABLE t (a LONGTEXT CHARACTER SET UCS2)", + noError: true, + }, + { + sql: `create table t (a long byte, b text unicode);`, + formatSQL: "CREATE TABLE t (a MEDIUMTEXT,b TEXT CHARACTER SET UCS2)", + noError: true, + }, + { + sql: `create table t (a long ascii, b long unicode);`, + formatSQL: "CREATE TABLE t (a MEDIUMTEXT CHARACTER SET LATIN1,b MEDIUMTEXT CHARACTER SET UCS2)", + noError: true, + }, + { + sql: `create table t (a text unicode, b mediumtext ascii, c int);`, + formatSQL: "CREATE TABLE t (a TEXT CHARACTER SET UCS2,b MEDIUMTEXT CHARACTER SET LATIN1,c INT)", + noError: true, + }, + } + + for _, c := range tc { + stmts, err := parser.ParseSqlText(c.sql) + if err != nil { + if c.noError { + t.Error(err) + continue + } + // 现在不会报错,而是解析为为解析节点 + // if err.Error() != c.errMsg { + // t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + // continue + // } + if len(stmts) > 0 { + if _, ok := stmts[0].(*ast.UnparsedStmt); !ok { + t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + continue + } + } + continue + } else { + if !c.noError { + if _, ok := stmts[0].(*ast.UnparsedStmt); !ok { + t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + continue + } + // t.Errorf("expect need error, but no error") + continue + } + buf := new(bytes.Buffer) + restoreCtx := parser_formate.NewRestoreCtx(parser_formate.RestoreKeyWordUppercase, buf) + if len(stmts) > 0 { + err = stmts[0].Restore(restoreCtx) + if nil != err { + t.Error(err) + continue + } + if buf.String() != c.formatSQL { + t.Errorf("expect sql format: %s; actual sql format: %s", c.formatSQL, buf.String()) + } + } + } + } +} + +func TestGeometryColumn(t *testing.T) { + parser := NewSplitter() + type testCase struct { + sql string + formatSQL string + noError bool + errMsg string + } + + tc := []testCase{ + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,g POINT)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g POINT)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g GEOMETRY)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g GEOMETRY)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g LINESTRING)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g LINESTRING)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g POLYGON)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g POLYGON)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g MULTIPOINT)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g MULTIPOINT)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g MULTILINESTRING)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g MULTILINESTRING)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g MULTIPOLYGON)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g MULTIPOLYGON)`, + noError: true, + }, + { + sql: `CREATE TABLE t (id INT PRIMARY KEY, g GEOMETRYCOLLECTION)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,g GEOMETRYCOLLECTION)`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g GEOMETRY`, + formatSQL: `ALTER TABLE t ADD COLUMN g GEOMETRY`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g POINT`, + formatSQL: `ALTER TABLE t ADD COLUMN g POINT`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g LINESTRING`, + formatSQL: `ALTER TABLE t ADD COLUMN g LINESTRING`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g POLYGON`, + formatSQL: `ALTER TABLE t ADD COLUMN g POLYGON`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g MULTIPOINT`, + formatSQL: `ALTER TABLE t ADD COLUMN g MULTIPOINT`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g MULTILINESTRING`, + formatSQL: `ALTER TABLE t ADD COLUMN g MULTILINESTRING`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g MULTIPOLYGON`, + formatSQL: `ALTER TABLE t ADD COLUMN g MULTIPOLYGON`, + noError: true, + }, + { + sql: `ALTER TABLE t ADD COLUMN g GEOMETRYCOLLECTION`, + formatSQL: `ALTER TABLE t ADD COLUMN g GEOMETRYCOLLECTION`, + noError: true, + }, + } + + for _, c := range tc { + stmts, err := parser.ParseSqlText(c.sql) + if err != nil { + if c.noError { + t.Error(err) + continue + } + if err.Error() != c.errMsg { + t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + continue + } + continue + } else { + if !c.noError { + t.Errorf("expect need error, but no error") + continue + } + buf := new(bytes.Buffer) + restoreCtx := parser_formate.NewRestoreCtx(parser_formate.RestoreKeyWordUppercase, buf) + if len(stmts) > 0 { + err = stmts[0].Restore(restoreCtx) + if nil != err { + t.Error(err) + continue + } + if buf.String() != c.formatSQL { + t.Errorf("expect sql format: %s; actual sql format: %s", c.formatSQL, buf.String()) + } + } + } + } +} + +func TestIndexConstraint(t *testing.T) { + parser := NewSplitter() + type testCase struct { + sql string + indexConstraint interface{} + } + tc := []testCase{ + { + sql: "CREATE TABLE t (id INT PRIMARY KEY, g POINT, SPATIAL INDEX(g))", + indexConstraint: ast.ConstraintSpatial, + }, + { + sql: "ALTER TABLE geom ADD SPATIAL INDEX(g)", + indexConstraint: ast.ConstraintSpatial, + }, + { + sql: "CREATE SPATIAL INDEX g ON geom (g)", + indexConstraint: ast.IndexKeyTypeSpatial, + }, + } + + for _, c := range tc { + isRight := false + stmt, err := parser.ParseSqlText(c.sql) + if err != nil { + t.Error(err) + continue + } else { + if len(stmt) == 0 { + t.Fatalf("result is empty") + } + switch stmt := stmt[0].(type) { + case *ast.CreateTableStmt: + indexConstraint, ok := c.indexConstraint.(ast.ConstraintType) + if !ok { + t.Errorf("sql: %s, indexConstraint is not ConstraintType", c.sql) + } + for _, constraint := range stmt.Constraints { + if constraint.Tp == indexConstraint { + isRight = true + } + } + case *ast.AlterTableStmt: + indexConstraint, ok := c.indexConstraint.(ast.ConstraintType) + if !ok { + t.Errorf("sql: %s, indexConstraint is not ConstraintType", c.sql) + } + for _, spec := range stmt.Specs { + if spec.Tp != ast.AlterTableAddConstraint || spec.Constraint == nil { + continue + } + if spec.Constraint.Tp == indexConstraint { + isRight = true + } + } + case *ast.CreateIndexStmt: + indexKey, ok := c.indexConstraint.(ast.IndexKeyType) + if !ok { + t.Errorf("sql: %s, indexConstraint is not indexKey", c.sql) + } + if stmt.KeyType == indexKey { + isRight = true + } + } + } + if !isRight { + t.Errorf("sql: %s, do not get expect indexConstraint: %v", c.sql, c.indexConstraint) + } + } +} + +func TestGeometryColumnIsNotReserved(t *testing.T) { + parser := NewSplitter() + type testCase struct { + sql string + formatSQL string + noError bool + errMsg string + } + + tc := []testCase{ + // point + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,point INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,point INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT point FROM t`, + formatSQL: `SELECT point FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (point) VALUES (1)`, + formatSQL: `INSERT INTO t (point) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET point=1`, + formatSQL: `UPDATE t SET point=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE point=1`, + formatSQL: `DELETE FROM t WHERE point=1`, + noError: true, + }, + // geometry + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,geometry INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,geometry INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT geometry FROM t`, + formatSQL: `SELECT geometry FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (geometry) VALUES (1)`, + formatSQL: `INSERT INTO t (geometry) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET geometry=1`, + formatSQL: `UPDATE t SET geometry=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE geometry=1`, + formatSQL: `DELETE FROM t WHERE geometry=1`, + noError: true, + }, + // LINESTRING + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,linestring INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,linestring INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT linestring FROM t`, + formatSQL: `SELECT linestring FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (linestring) VALUES (1)`, + formatSQL: `INSERT INTO t (linestring) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET linestring=1`, + formatSQL: `UPDATE t SET linestring=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE linestring=1`, + formatSQL: `DELETE FROM t WHERE linestring=1`, + noError: true, + }, + // POLYGON + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,polygon INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,polygon INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT polygon FROM t`, + formatSQL: `SELECT polygon FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (polygon) VALUES (1)`, + formatSQL: `INSERT INTO t (polygon) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET polygon=1`, + formatSQL: `UPDATE t SET polygon=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE polygon=1`, + formatSQL: `DELETE FROM t WHERE polygon=1`, + noError: true, + }, + // MULTIPOINT + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,multipoint INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,multipoint INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT multipoint FROM t`, + formatSQL: `SELECT multipoint FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (multipoint) VALUES (1)`, + formatSQL: `INSERT INTO t (multipoint) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET multipoint=1`, + formatSQL: `UPDATE t SET multipoint=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE multipoint=1`, + formatSQL: `DELETE FROM t WHERE multipoint=1`, + noError: true, + }, + // MULTILINESTRING + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,multilinestring INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,multilinestring INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT multilinestring FROM t`, + formatSQL: `SELECT multilinestring FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (multilinestring) VALUES (1)`, + formatSQL: `INSERT INTO t (multilinestring) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET multilinestring=1`, + formatSQL: `UPDATE t SET multilinestring=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE multilinestring=1`, + formatSQL: `DELETE FROM t WHERE multilinestring=1`, + noError: true, + }, + // MULTIPOLYGON + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,multipolygon INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,multipolygon INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT multipolygon FROM t`, + formatSQL: `SELECT multipolygon FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (multipolygon) VALUES (1)`, + formatSQL: `INSERT INTO t (multipolygon) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET multipolygon=1`, + formatSQL: `UPDATE t SET multipolygon=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE multipolygon=1`, + formatSQL: `DELETE FROM t WHERE multipolygon=1`, + noError: true, + }, + // GEOMETRYCOLLECTION + { + sql: `CREATE TABLE t (id INT PRIMARY KEY,geometrycollection INT(8) NOT NULL)`, + formatSQL: `CREATE TABLE t (id INT PRIMARY KEY,geometrycollection INT(8) NOT NULL)`, + noError: true, + }, + { + sql: `SELECT geometrycollection FROM t`, + formatSQL: `SELECT geometrycollection FROM t`, + noError: true, + }, + { + sql: `INSERT INTO t (geometrycollection) VALUES (1)`, + formatSQL: `INSERT INTO t (geometrycollection) VALUES (1)`, + noError: true, + }, + { + sql: `UPDATE t SET geometrycollection=1`, + formatSQL: `UPDATE t SET geometrycollection=1`, + noError: true, + }, + { + sql: `DELETE FROM t WHERE geometrycollection=1`, + formatSQL: `DELETE FROM t WHERE geometrycollection=1`, + noError: true, + }, + } + + for _, c := range tc { + stmt, err := parser.ParseSqlText(c.sql) + if len(stmt) == 0 { + t.Fatalf("result is empty") + } + if err != nil { + if c.noError { + t.Error(err) + continue + } + // 现在不会报错,而是解析为为解析节点 + // if err.Error() != c.errMsg { + // t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + // continue + // } + if _, ok := stmt[0].(*ast.UnparsedStmt); !ok { + t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + continue + } + // if err.Error() != c.errMsg { + // t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + // continue + // } + continue + } else { + if !c.noError { + // t.Errorf("expect need error, but no error") + if _, ok := stmt[0].(*ast.UnparsedStmt); !ok { + t.Errorf("expect error message: %s; actual error message: %s", c.errMsg, err.Error()) + continue + } + continue + } + buf := new(bytes.Buffer) + restoreCtx := parser_formate.NewRestoreCtx(parser_formate.RestoreKeyWordUppercase, buf) + + err = stmt[0].Restore(restoreCtx) + if nil != err { + t.Error(err) + continue + } + if buf.String() != c.formatSQL { + t.Errorf("expect sql format: %s; actual sql format: %s", c.formatSQL, buf.String()) + } + } + } +} diff --git a/sqle/driver/mysql/splitter/splitter_test_1.sql b/sqle/driver/mysql/splitter/splitter_test_1.sql new file mode 100644 index 0000000000..14120b706d --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter_test_1.sql @@ -0,0 +1,61 @@ +/* DELIMITER str */ +/* 注释中定义分隔符 预期不会被检测为分隔符语法 */ +DELIMITER --good +-- DELIMITER str + +/* 分隔符在注释中,预期不被分割 */ +-- --good +/* --good */ +DROP PROCEDURE IF EXISTS `_GS_GM_Check` --good +/* 分隔符在SQL语句中或注释中,预期不会被分割 */ +/* 分隔符定义语法在SQL语句中,预期不会被识别 */ +CREATE DELIMITER = `--good`@`%` PROCEDURE `DELIMITER`(vi_uid INT,vi_pwd VARCHAR(32),vi_ip VARCHAR(100),OUT vo_level INT,OUT vo_code INT) +BEGIN +/* 分隔符与语句粘连,预期会被分割 */ + END--good +/* 切换分隔符 */ +DELIMITER ; +CREATE FUNCTION hello (s CHAR(20)); +CREATE FUNCTION hello (s CHAR(20)) ; +-- 切换分隔符 +DELIMITER // +use test // +/* 多条语句合并提交,预期切分结果会包含分隔符之间的多条sql */ +SET @sql = 'SELECT * FROM employees WHERE salary = 2321.21'; +SET @result = @sql; +PREPARE stmt FROM @result; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +CREATE DELIMITER = `//`@`%` PROCEDURE `DELIMITER`(vi_uid INT,vi_pwd VARCHAR(32),vi_ip VARCHAR(100),OUT vo_level INT,OUT vo_code INT) +BEGIN + -- 分隔符与语句粘连,预期会被分割 + END; +// +DELIMITER ; + +CREATE TABLE account (acct_num INT, amount DECIMAL(10,2)); /* ; */ + +CREATE TRIGGER ins_sum BEFORE /* ; */INSERT ON account + FOR EACH ROW SET @sum = @sum + NEW.amount; + +SET @sum = 0; + +INSERT INTO account VALUES(137,14.98)/* ; */,(141,1937.50),(97,-100.00);/* ; */ +SELECT @sum AS ';';/* ; */ +DROP TRIGGER test.ins_sum;/* ; */ +CREATE TRIGGER ins_transaction BEFORE INSERT ON account + /* ; */ FOR EACH ROW PRECEDES ins_sum + SET + @deposits = @deposits + IF(NEW.amount>0,NEW.amount,0), + @withdrawals = @withdrawals + IF(NEW.amount<0,-NEW.amount,0); +delimiter // +CREATE TRIGGER upd_check BEFORE UPDATE ON account + FOR EACH ROW + BEGIN + IF NEW.amount < 0 THEN + SET NEW.amount = 0; + ELSEIF NEW.amount > 100 THEN + SET NEW.amount = 100; + END IF; + END// +delimiter ; \ No newline at end of file diff --git a/sqle/driver/mysql/splitter/splitter_test_2.sql b/sqle/driver/mysql/splitter/splitter_test_2.sql new file mode 100644 index 0000000000..81983f57b9 --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter_test_2.sql @@ -0,0 +1,61 @@ +/* \d str */ +/* 注释中定义分隔符 预期不会被检测为分隔符语法 */ +\d --good +-- \d str + +/* 分隔符在注释中,预期不被分割 */ +-- --good +/* --good */ +DROP PROCEDURE IF EXISTS `_GS_GM_Check` --good +/* 分隔符在SQL语句中或注释中,预期不会被分割 */ +/* 分隔符定义语法在SQL语句中,预期不会被识别 */ +CREATE \d = `--good`@`%` PROCEDURE `\d`(vi_uid INT,vi_pwd VARCHAR(32),vi_ip VARCHAR(100),OUT vo_level INT,OUT vo_code INT) +BEGIN +/* 分隔符与语句粘连,预期会被分割 */ + END--good +/* 切换分隔符 */ +\d ; +CREATE FUNCTION hello (s CHAR(20)); +CREATE FUNCTION hello (s CHAR(20)) ; +-- 切换分隔符 +\d // +use test // +/* 多条语句合并提交,预期切分结果会包含分隔符之间的多条sql */ +SET @sql = 'SELECT * FROM employees WHERE salary = 2321.21'; +SET @result = @sql; +PREPARE stmt FROM @result; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +CREATE \d = `//`@`%` PROCEDURE `\d`(vi_uid INT,vi_pwd VARCHAR(32),vi_ip VARCHAR(100),OUT vo_level INT,OUT vo_code INT) +BEGIN + -- 分隔符与语句粘连,预期会被分割 + END; +// +\d ; + +CREATE TABLE account (acct_num INT, amount DECIMAL(10,2)); /* ; */ + +CREATE TRIGGER ins_sum BEFORE /* ; */INSERT ON account + FOR EACH ROW SET @sum = @sum + NEW.amount; + +SET @sum = 0; + +INSERT INTO account VALUES(137,14.98)/* ; */,(141,1937.50),(97,-100.00);/* ; */ +SELECT @sum AS ';';/* ; */ +DROP TRIGGER test.ins_sum;/* ; */ +CREATE TRIGGER ins_transaction BEFORE INSERT ON account + /* ; */ FOR EACH ROW PRECEDES ins_sum + SET + @deposits = @deposits + IF(NEW.amount>0,NEW.amount,0), + @withdrawals = @withdrawals + IF(NEW.amount<0,-NEW.amount,0); +delimiter // +CREATE TRIGGER upd_check BEFORE UPDATE ON account + FOR EACH ROW + BEGIN + IF NEW.amount < 0 THEN + SET NEW.amount = 0; + ELSEIF NEW.amount > 100 THEN + SET NEW.amount = 100; + END IF; + END// +delimiter ; \ No newline at end of file diff --git a/sqle/driver/mysql/splitter/splitter_test_3.sql b/sqle/driver/mysql/splitter/splitter_test_3.sql new file mode 100644 index 0000000000..3fdfd18216 --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter_test_3.sql @@ -0,0 +1,83 @@ +-- 1 +CREATE PROCEDURE nested_example() +BEGIN + DECLARE v_outer_variable INT DEFAULT 0; + + -- 外层 BEGIN ... END 块 + BEGIN + DECLARE v_inner_variable INT DEFAULT 10; + + -- 内层 BEGIN ... END 块 + BEGIN + DECLARE v_nested_variable INT DEFAULT 20; + + IF v_outer_variable = 0 THEN + SET v_outer_variable = v_inner_variable + v_nested_variable; + END IF; + END; -- 内层块结束 + WHILE v1 > 0 DO + SET v1 = v1 - 1; + END WHILE; + IF v_outer_variable > 0 THEN + SET v_outer_variable = v_outer_variable * 2; + END IF; + END; -- 外层块结束 +END; +-- 2 +CREATE PROCEDURE example_procedure() +BEGIN + DECLARE v_variable INT DEFAULT 0; + + IF v_variable = 0 THEN + SET v_variable = 1; + ELSEIF v_variable = 1 THEN + SET v_variable = 2; + ELSE + SET v_variable = 0; + END IF; + + -- 其他处理语句 +END; +-- 3 +CREATE PROCEDURE doiterate(p1 INT) +BEGIN + label1: LOOP + SET p1 = p1 + 1; + IF p1 < 10 THEN + ITERATE label1; + END IF; + LEAVE label1; + END LOOP label1; + SET @x = p1; +END; +-- 4 +CREATE PROCEDURE complex_loops_example() +BEGIN + DECLARE v_counter INT DEFAULT 0; + DECLARE v_limit INT DEFAULT 5; + DECLARE v_sum INT DEFAULT 0; + + -- 使用 LOOP 结构 + loop_label: LOOP + SET v_counter = v_counter + 1; + + -- 使用 WHILE 结构 + WHILE v_counter <= v_limit DO + SET v_sum = v_sum + v_counter; + + -- 使用 REPEAT 结构 + REPEAT + SET v_counter = v_counter + 1; + UNTIL v_counter > v_limit + END REPEAT; + END WHILE; + + -- 退出 LOOP 的条件 + IF v_counter > v_limit THEN + LEAVE loop_label; + END IF; + END LOOP; + + -- 输出结果 + SELECT v_sum AS total_sum; +END; \ No newline at end of file diff --git a/sqle/driver/mysql/splitter/splitter_test_skip_quoted_delimiter.sql b/sqle/driver/mysql/splitter/splitter_test_skip_quoted_delimiter.sql new file mode 100644 index 0000000000..e3081c7a3d --- /dev/null +++ b/sqle/driver/mysql/splitter/splitter_test_skip_quoted_delimiter.sql @@ -0,0 +1,26 @@ +delimiter abcd +select "abcd" abcd +select 'abcd' abcd +delimiter "'efgh'" +select 'abcd' 'efgh' +select "'abcd'" 'efgh' +delimiter "`abcd`" +select '`abcd`' `abcd` +select "`abcd`" `abcd` +delimiter `"efgh"` +select '"abcd"' "efgh" +select "abcd" "efgh" +delimiter `"abcd";` +select '"abcd";' "abcd"; +select '"aacd";' "abcd"; +delimiter "`efgh`;" +select "`abcd`;" `efgh`; +select '`abcd`;' `efgh`; +delimiter "'abcd';" +select "'abcd';" 'abcd'; +select "'abcd1';" 'abcd'; +delimiter ab +select "ab'abcd';" ab +select "ab'abbd';" ab +select 'abcd'; ab +select 'ab'; ab \ No newline at end of file diff --git a/sqle/driver/mysql/util/parser_helper.go b/sqle/driver/mysql/util/parser_helper.go index cb85f6679f..a06479e314 100644 --- a/sqle/driver/mysql/util/parser_helper.go +++ b/sqle/driver/mysql/util/parser_helper.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" + "github.com/actiontech/sqle/sqle/driver/mysql/splitter" "github.com/pingcap/parser" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/format" @@ -19,8 +20,7 @@ import ( ) func ParseSql(sql string) ([]ast.StmtNode, error) { - p := parser.New() - stmts, _, err := p.PerfectParse(sql, "", "") + stmts, err := splitter.NewSplitter().ParseSqlText(sql) if err != nil { return nil, err } diff --git a/vendor/github.com/pingcap/parser/parser_extension.go b/vendor/github.com/pingcap/parser/parser_extension.go new file mode 100644 index 0000000000..81fc193c77 --- /dev/null +++ b/vendor/github.com/pingcap/parser/parser_extension.go @@ -0,0 +1,7 @@ +package parser + +import "github.com/pingcap/parser/ast" + +func (p Parser) Result() []ast.StmtNode { + return p.result +} diff --git a/vendor/github.com/pingcap/parser/perfect_parser.go b/vendor/github.com/pingcap/parser/perfect_parser.go index e49d98acaa..31026e7d9e 100644 --- a/vendor/github.com/pingcap/parser/perfect_parser.go +++ b/vendor/github.com/pingcap/parser/perfect_parser.go @@ -23,7 +23,7 @@ func (parser *Parser) PerfectParse(sql, charset, collation string) (stmt []ast.S } stmt = append(stmt, stmts...) } - parser.startLineOffset = parser.lexer.r.pos().Line - 1 + parser.startLineOffset += parser.lexer.r.pos().Line - 1 // The origin SQL text(input args `sql`) consists of many SQL segments, // each SQL segments is a complete SQL and be parsed into `ast.StmtNode`. // diff --git a/vendor/github.com/pingcap/parser/scanner_extension .go b/vendor/github.com/pingcap/parser/scanner_extension .go new file mode 100644 index 0000000000..0dad382699 --- /dev/null +++ b/vendor/github.com/pingcap/parser/scanner_extension .go @@ -0,0 +1,68 @@ +package parser + +// 这个Reset方法在原有reset()方法上增加了将最后扫描的偏移量置零 +func (s *Scanner) Reset(sql string) { + s.reset(sql) + s.lastScanOffset = 0 +} + +// 该方法返回Scanner最后扫描到的位置 +func (s *Scanner) Offset() int { + return s.lastScanOffset +} + +// 该方法修改Scanner最后扫描到的位置 +func (s *Scanner) SetCursor(offset int) { + s.lastScanOffset = offset +} + +const ( + Identifier int = identifier + YyEOFCode int = yyEOFCode + YyDefault int = yyDefault + IfKwd int = ifKwd + CaseKwd int = caseKwd + Repeat int = repeat + Begin int = begin + End int = end + StringLit int = stringLit + Invalid int = invalid +) + +type TokenValue yySymType + +type Token struct { + tokenType int + tokenValue *yySymType +} + +func (t Token) Ident() string { + return t.tokenValue.ident +} + +func (t Token) TokenType() int { + return t.tokenType +} + +func (s *Scanner) NextToken() *Token { + tokenValue := &yySymType{} + tokenType := s.Lex(tokenValue) + return &Token{ + tokenType: tokenType, + tokenValue: tokenValue, + } +} + +func (s *Scanner) ScannedLines() int { + return s.r.pos().Line - 1 +} + +func (s *Scanner) Text() string { + return s.r.s +} + +func (s *Scanner) HandleInvalid() { + if s.lastScanOffset == s.r.p.Offset { + s.r.inc() + } +} diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c b/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c deleted file mode 100644 index f532ef0e4d..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.c +++ /dev/null @@ -1,2144 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow (danshu@microsoft.com) - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#include -#include -#include -#ifdef __unix__ -#include /* make sure macros like _BIG_ENDIAN visible */ -#endif -#endif - -#ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_INCLUDE_SHA1_C -#endif - -#ifndef SHA1DC_INIT_SAFE_HASH_DEFAULT -#define SHA1DC_INIT_SAFE_HASH_DEFAULT 1 -#endif - -#include "sha1.h" -#include "ubc_check.h" - -#if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \ - defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || \ - defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__) || \ - defined(__386) || defined(_M_X64) || defined(_M_AMD64)) -#define SHA1DC_ON_INTEL_LIKE_PROCESSOR -#endif - -/* - Because Little-Endian architectures are most common, - we only set SHA1DC_BIGENDIAN if one of these conditions is met. - Note that all MSFT platforms are little endian, - so none of these will be defined under the MSC compiler. - If you are compiling on a big endian platform and your compiler does not define one of these, - you will have to add whatever macros your tool chain defines to indicate Big-Endianness. - */ - -#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) -/* - * Should detect Big Endian under GCC since at least 4.6.0 (gcc svn - * rev #165881). See - * https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html - * - * This also works under clang since 3.2, it copied the GCC-ism. See - * clang.git's 3b198a97d2 ("Preprocessor: add __BYTE_ORDER__ - * predefined macro", 2012-07-27) - */ -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike */ -#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) -/* - * Should detect Big Endian under glibc.git since 14245eb70e ("entered - * into RCS", 1992-11-25). Defined in which will have been - * brought in by standard headers. See glibc.git and - * https://sourceforge.net/p/predef/wiki/Endianness/ - */ -#if __BYTE_ORDER == __BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc */ -#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) -/* - * *BSD and newlib (embedded linux, cygwin, etc). - * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents - * this condition from matching with Solaris/sparc. - * (Solaris defines only one endian macro) - */ -#if _BYTE_ORDER == _BIG_ENDIAN -#define SHA1DC_BIGENDIAN -#endif - -/* Not under GCC-alike or glibc or *BSD or newlib */ -#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ - defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ - defined(__sparc)) -/* - * Should define Big Endian for a whitelist of known processors. See - * https://sourceforge.net/p/predef/wiki/Endianness/ and - * http://www.oracle.com/technetwork/server-storage/solaris/portingtosolaris-138514.html - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or */ -#elif (defined(_AIX) || defined(__hpux)) - -/* - * Defines Big Endian on a whitelist of OSs that are known to be Big - * Endian-only. See - * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/ - */ -#define SHA1DC_BIGENDIAN - -/* Not under GCC-alike or glibc or *BSD or newlib or or */ -#elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -/* - * As a last resort before we do anything else we're not 100% sure - * about below, we blacklist specific processors here. We could add - * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo - */ -#else /* Not under GCC-alike or glibc or *BSD or newlib or or or */ - -/* We do nothing more here for now */ -/*#error "Uncomment this to see if you fall through all the detection"*/ - -#endif /* Big Endian detection */ - -#if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN)) -#undef SHA1DC_BIGENDIAN -#endif -#if (defined(SHA1DC_FORCE_BIGENDIAN) && !defined(SHA1DC_BIGENDIAN)) -#define SHA1DC_BIGENDIAN -#endif -/*ENDIANNESS SELECTION*/ - -#ifndef SHA1DC_FORCE_ALIGNED_ACCESS -#if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) -#define SHA1DC_ALLOW_UNALIGNED_ACCESS -#endif /*UNALIGNED ACCESS DETECTION*/ -#endif /*FORCE ALIGNED ACCESS*/ - -#define rotate_right(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) -#define rotate_left(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - -#define sha1_bswap32(x) \ - { \ - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); \ - x = (x << 16) | (x >> 16); \ - } - -#define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1)) - -#ifdef SHA1DC_BIGENDIAN -#define sha1_load(m, t, temp) \ - { \ - temp = m[t]; \ - } -#else -#define sha1_load(m, t, temp) \ - { \ - temp = m[t]; \ - sha1_bswap32(temp); \ - } -#endif - -#define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x - -#define sha1_f1(b, c, d) ((d) ^ ((b) & ((c) ^ (d)))) -#define sha1_f2(b, c, d) ((b) ^ (c) ^ (d)) -#define sha1_f3(b, c, d) (((b) & (c)) + ((d) & ((b) ^ (c)))) -#define sha1_f4(b, c, d) ((b) ^ (c) ^ (d)) - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999 + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1 + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC + m[t]; \ - b = rotate_left(b, 30); \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \ - { \ - e += rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6 + m[t]; \ - b = rotate_left(b, 30); \ - } - -#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999 + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1 + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC + m[t]; \ - } -#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \ - { \ - b = rotate_right(b, 30); \ - e -= rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6 + m[t]; \ - } - -#define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \ - { \ - sha1_load(m, t, temp); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f1(b, c, d) + 0x5A827999; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f2(b, c, d) + 0x6ED9EBA1; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f3(b, c, d) + 0x8F1BBCDC; \ - b = rotate_left(b, 30); \ - } - -#define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \ - { \ - temp = sha1_mix(W, t); \ - sha1_store(W, t, temp); \ - e += temp + rotate_left(a, 5) + sha1_f4(b, c, d) + 0xCA62C1D6; \ - b = rotate_left(b, 30); \ - } - -#define SHA1_STORE_STATE(i) \ - states[i][0] = a; \ - states[i][1] = b; \ - states[i][2] = c; \ - states[i][3] = d; \ - states[i][4] = e; - -#ifdef BUILDNOCOLLDETECTSHA1COMPRESSION -void sha1_compression(uint32_t ihv[5], const uint32_t m[16]) -{ - uint32_t W[80]; - uint32_t a, b, c, d, e; - unsigned i; - - memcpy(W, m, 16 * 4); - for (i = 16; i < 80; ++i) - W[i] = sha1_mix(W, i); - - a = ihv[0]; - b = ihv[1]; - c = ihv[2]; - d = ihv[3]; - e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} -#endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/ - -static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18); - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19); - - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38); - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39); - - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58); - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59); - - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78); - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} - -void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5]) -{ - uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4]; - uint32_t temp; - -#ifdef DOSTORESTATE00 - SHA1_STORE_STATE(0) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp); - -#ifdef DOSTORESTATE01 - SHA1_STORE_STATE(1) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp); - -#ifdef DOSTORESTATE02 - SHA1_STORE_STATE(2) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp); - -#ifdef DOSTORESTATE03 - SHA1_STORE_STATE(3) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp); - -#ifdef DOSTORESTATE04 - SHA1_STORE_STATE(4) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp); - -#ifdef DOSTORESTATE05 - SHA1_STORE_STATE(5) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp); - -#ifdef DOSTORESTATE06 - SHA1_STORE_STATE(6) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp); - -#ifdef DOSTORESTATE07 - SHA1_STORE_STATE(7) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp); - -#ifdef DOSTORESTATE08 - SHA1_STORE_STATE(8) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp); - -#ifdef DOSTORESTATE09 - SHA1_STORE_STATE(9) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp); - -#ifdef DOSTORESTATE10 - SHA1_STORE_STATE(10) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp); - -#ifdef DOSTORESTATE11 - SHA1_STORE_STATE(11) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp); - -#ifdef DOSTORESTATE12 - SHA1_STORE_STATE(12) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp); - -#ifdef DOSTORESTATE13 - SHA1_STORE_STATE(13) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp); - -#ifdef DOSTORESTATE14 - SHA1_STORE_STATE(14) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp); - -#ifdef DOSTORESTATE15 - SHA1_STORE_STATE(15) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp); - -#ifdef DOSTORESTATE16 - SHA1_STORE_STATE(16) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp); - -#ifdef DOSTORESTATE17 - SHA1_STORE_STATE(17) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp); - -#ifdef DOSTORESTATE18 - SHA1_STORE_STATE(18) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp); - -#ifdef DOSTORESTATE19 - SHA1_STORE_STATE(19) -#endif - SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp); - -#ifdef DOSTORESTATE20 - SHA1_STORE_STATE(20) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp); - -#ifdef DOSTORESTATE21 - SHA1_STORE_STATE(21) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp); - -#ifdef DOSTORESTATE22 - SHA1_STORE_STATE(22) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp); - -#ifdef DOSTORESTATE23 - SHA1_STORE_STATE(23) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp); - -#ifdef DOSTORESTATE24 - SHA1_STORE_STATE(24) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp); - -#ifdef DOSTORESTATE25 - SHA1_STORE_STATE(25) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp); - -#ifdef DOSTORESTATE26 - SHA1_STORE_STATE(26) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp); - -#ifdef DOSTORESTATE27 - SHA1_STORE_STATE(27) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp); - -#ifdef DOSTORESTATE28 - SHA1_STORE_STATE(28) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp); - -#ifdef DOSTORESTATE29 - SHA1_STORE_STATE(29) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp); - -#ifdef DOSTORESTATE30 - SHA1_STORE_STATE(30) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp); - -#ifdef DOSTORESTATE31 - SHA1_STORE_STATE(31) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp); - -#ifdef DOSTORESTATE32 - SHA1_STORE_STATE(32) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp); - -#ifdef DOSTORESTATE33 - SHA1_STORE_STATE(33) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp); - -#ifdef DOSTORESTATE34 - SHA1_STORE_STATE(34) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp); - -#ifdef DOSTORESTATE35 - SHA1_STORE_STATE(35) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp); - -#ifdef DOSTORESTATE36 - SHA1_STORE_STATE(36) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp); - -#ifdef DOSTORESTATE37 - SHA1_STORE_STATE(37) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp); - -#ifdef DOSTORESTATE38 - SHA1_STORE_STATE(38) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp); - -#ifdef DOSTORESTATE39 - SHA1_STORE_STATE(39) -#endif - SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp); - -#ifdef DOSTORESTATE40 - SHA1_STORE_STATE(40) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp); - -#ifdef DOSTORESTATE41 - SHA1_STORE_STATE(41) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp); - -#ifdef DOSTORESTATE42 - SHA1_STORE_STATE(42) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp); - -#ifdef DOSTORESTATE43 - SHA1_STORE_STATE(43) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp); - -#ifdef DOSTORESTATE44 - SHA1_STORE_STATE(44) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp); - -#ifdef DOSTORESTATE45 - SHA1_STORE_STATE(45) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp); - -#ifdef DOSTORESTATE46 - SHA1_STORE_STATE(46) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp); - -#ifdef DOSTORESTATE47 - SHA1_STORE_STATE(47) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp); - -#ifdef DOSTORESTATE48 - SHA1_STORE_STATE(48) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp); - -#ifdef DOSTORESTATE49 - SHA1_STORE_STATE(49) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp); - -#ifdef DOSTORESTATE50 - SHA1_STORE_STATE(50) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp); - -#ifdef DOSTORESTATE51 - SHA1_STORE_STATE(51) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp); - -#ifdef DOSTORESTATE52 - SHA1_STORE_STATE(52) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp); - -#ifdef DOSTORESTATE53 - SHA1_STORE_STATE(53) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp); - -#ifdef DOSTORESTATE54 - SHA1_STORE_STATE(54) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp); - -#ifdef DOSTORESTATE55 - SHA1_STORE_STATE(55) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp); - -#ifdef DOSTORESTATE56 - SHA1_STORE_STATE(56) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp); - -#ifdef DOSTORESTATE57 - SHA1_STORE_STATE(57) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp); - -#ifdef DOSTORESTATE58 - SHA1_STORE_STATE(58) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp); - -#ifdef DOSTORESTATE59 - SHA1_STORE_STATE(59) -#endif - SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp); - -#ifdef DOSTORESTATE60 - SHA1_STORE_STATE(60) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp); - -#ifdef DOSTORESTATE61 - SHA1_STORE_STATE(61) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp); - -#ifdef DOSTORESTATE62 - SHA1_STORE_STATE(62) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp); - -#ifdef DOSTORESTATE63 - SHA1_STORE_STATE(63) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp); - -#ifdef DOSTORESTATE64 - SHA1_STORE_STATE(64) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp); - -#ifdef DOSTORESTATE65 - SHA1_STORE_STATE(65) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp); - -#ifdef DOSTORESTATE66 - SHA1_STORE_STATE(66) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp); - -#ifdef DOSTORESTATE67 - SHA1_STORE_STATE(67) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp); - -#ifdef DOSTORESTATE68 - SHA1_STORE_STATE(68) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp); - -#ifdef DOSTORESTATE69 - SHA1_STORE_STATE(69) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp); - -#ifdef DOSTORESTATE70 - SHA1_STORE_STATE(70) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp); - -#ifdef DOSTORESTATE71 - SHA1_STORE_STATE(71) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp); - -#ifdef DOSTORESTATE72 - SHA1_STORE_STATE(72) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp); - -#ifdef DOSTORESTATE73 - SHA1_STORE_STATE(73) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp); - -#ifdef DOSTORESTATE74 - SHA1_STORE_STATE(74) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp); - -#ifdef DOSTORESTATE75 - SHA1_STORE_STATE(75) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp); - -#ifdef DOSTORESTATE76 - SHA1_STORE_STATE(76) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp); - -#ifdef DOSTORESTATE77 - SHA1_STORE_STATE(77) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp); - -#ifdef DOSTORESTATE78 - SHA1_STORE_STATE(78) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp); - -#ifdef DOSTORESTATE79 - SHA1_STORE_STATE(79) -#endif - SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp); - - ihv[0] += a; - ihv[1] += b; - ihv[2] += c; - ihv[3] += d; - ihv[4] += e; -} - -#define SHA1_RECOMPRESS(t) \ - static void sha1recompress_fast_##t(uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \ - { \ - uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \ - if (t > 79) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \ - if (t > 78) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \ - if (t > 77) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \ - if (t > 76) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \ - if (t > 75) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \ - if (t > 74) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \ - if (t > 73) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \ - if (t > 72) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \ - if (t > 71) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \ - if (t > 70) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \ - if (t > 69) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \ - if (t > 68) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \ - if (t > 67) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \ - if (t > 66) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \ - if (t > 65) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \ - if (t > 64) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \ - if (t > 63) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \ - if (t > 62) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \ - if (t > 61) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \ - if (t > 60) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \ - if (t > 59) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \ - if (t > 58) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \ - if (t > 57) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \ - if (t > 56) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \ - if (t > 55) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \ - if (t > 54) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \ - if (t > 53) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \ - if (t > 52) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \ - if (t > 51) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \ - if (t > 50) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \ - if (t > 49) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \ - if (t > 48) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \ - if (t > 47) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \ - if (t > 46) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \ - if (t > 45) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \ - if (t > 44) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \ - if (t > 43) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \ - if (t > 42) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \ - if (t > 41) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \ - if (t > 40) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \ - if (t > 39) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \ - if (t > 38) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \ - if (t > 37) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \ - if (t > 36) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \ - if (t > 35) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \ - if (t > 34) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \ - if (t > 33) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \ - if (t > 32) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \ - if (t > 31) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \ - if (t > 30) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \ - if (t > 29) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \ - if (t > 28) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \ - if (t > 27) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \ - if (t > 26) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \ - if (t > 25) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \ - if (t > 24) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \ - if (t > 23) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \ - if (t > 22) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \ - if (t > 21) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \ - if (t > 20) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \ - if (t > 19) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \ - if (t > 18) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \ - if (t > 17) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \ - if (t > 16) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \ - if (t > 15) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \ - if (t > 14) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \ - if (t > 13) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \ - if (t > 12) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \ - if (t > 11) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \ - if (t > 10) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \ - if (t > 9) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \ - if (t > 8) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \ - if (t > 7) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \ - if (t > 6) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \ - if (t > 5) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \ - if (t > 4) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \ - if (t > 3) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \ - if (t > 2) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \ - if (t > 1) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \ - if (t > 0) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \ - ihvin[0] = a; \ - ihvin[1] = b; \ - ihvin[2] = c; \ - ihvin[3] = d; \ - ihvin[4] = e; \ - a = state[0]; \ - b = state[1]; \ - c = state[2]; \ - d = state[3]; \ - e = state[4]; \ - if (t <= 0) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \ - if (t <= 1) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \ - if (t <= 2) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \ - if (t <= 3) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \ - if (t <= 4) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \ - if (t <= 5) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \ - if (t <= 6) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \ - if (t <= 7) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \ - if (t <= 8) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \ - if (t <= 9) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \ - if (t <= 10) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \ - if (t <= 11) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \ - if (t <= 12) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \ - if (t <= 13) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \ - if (t <= 14) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \ - if (t <= 15) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \ - if (t <= 16) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \ - if (t <= 17) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \ - if (t <= 18) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \ - if (t <= 19) \ - HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \ - if (t <= 20) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \ - if (t <= 21) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \ - if (t <= 22) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \ - if (t <= 23) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \ - if (t <= 24) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \ - if (t <= 25) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \ - if (t <= 26) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \ - if (t <= 27) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \ - if (t <= 28) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \ - if (t <= 29) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \ - if (t <= 30) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \ - if (t <= 31) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \ - if (t <= 32) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \ - if (t <= 33) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \ - if (t <= 34) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \ - if (t <= 35) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \ - if (t <= 36) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \ - if (t <= 37) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \ - if (t <= 38) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \ - if (t <= 39) \ - HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \ - if (t <= 40) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \ - if (t <= 41) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \ - if (t <= 42) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \ - if (t <= 43) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \ - if (t <= 44) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \ - if (t <= 45) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \ - if (t <= 46) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \ - if (t <= 47) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \ - if (t <= 48) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \ - if (t <= 49) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \ - if (t <= 50) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \ - if (t <= 51) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \ - if (t <= 52) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \ - if (t <= 53) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \ - if (t <= 54) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \ - if (t <= 55) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \ - if (t <= 56) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \ - if (t <= 57) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \ - if (t <= 58) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \ - if (t <= 59) \ - HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \ - if (t <= 60) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \ - if (t <= 61) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \ - if (t <= 62) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \ - if (t <= 63) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \ - if (t <= 64) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \ - if (t <= 65) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \ - if (t <= 66) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \ - if (t <= 67) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \ - if (t <= 68) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \ - if (t <= 69) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \ - if (t <= 70) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \ - if (t <= 71) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \ - if (t <= 72) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \ - if (t <= 73) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \ - if (t <= 74) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \ - if (t <= 75) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \ - if (t <= 76) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \ - if (t <= 77) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \ - if (t <= 78) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \ - if (t <= 79) \ - HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \ - ihvout[0] = ihvin[0] + a; \ - ihvout[1] = ihvin[1] + b; \ - ihvout[2] = ihvin[2] + c; \ - ihvout[3] = ihvin[3] + d; \ - ihvout[4] = ihvin[4] + e; \ - } - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4127) /* Compiler complains about the checks in the above macro being constant. */ -#endif - -#ifdef DOSTORESTATE0 -SHA1_RECOMPRESS(0) -#endif - -#ifdef DOSTORESTATE1 -SHA1_RECOMPRESS(1) -#endif - -#ifdef DOSTORESTATE2 -SHA1_RECOMPRESS(2) -#endif - -#ifdef DOSTORESTATE3 -SHA1_RECOMPRESS(3) -#endif - -#ifdef DOSTORESTATE4 -SHA1_RECOMPRESS(4) -#endif - -#ifdef DOSTORESTATE5 -SHA1_RECOMPRESS(5) -#endif - -#ifdef DOSTORESTATE6 -SHA1_RECOMPRESS(6) -#endif - -#ifdef DOSTORESTATE7 -SHA1_RECOMPRESS(7) -#endif - -#ifdef DOSTORESTATE8 -SHA1_RECOMPRESS(8) -#endif - -#ifdef DOSTORESTATE9 -SHA1_RECOMPRESS(9) -#endif - -#ifdef DOSTORESTATE10 -SHA1_RECOMPRESS(10) -#endif - -#ifdef DOSTORESTATE11 -SHA1_RECOMPRESS(11) -#endif - -#ifdef DOSTORESTATE12 -SHA1_RECOMPRESS(12) -#endif - -#ifdef DOSTORESTATE13 -SHA1_RECOMPRESS(13) -#endif - -#ifdef DOSTORESTATE14 -SHA1_RECOMPRESS(14) -#endif - -#ifdef DOSTORESTATE15 -SHA1_RECOMPRESS(15) -#endif - -#ifdef DOSTORESTATE16 -SHA1_RECOMPRESS(16) -#endif - -#ifdef DOSTORESTATE17 -SHA1_RECOMPRESS(17) -#endif - -#ifdef DOSTORESTATE18 -SHA1_RECOMPRESS(18) -#endif - -#ifdef DOSTORESTATE19 -SHA1_RECOMPRESS(19) -#endif - -#ifdef DOSTORESTATE20 -SHA1_RECOMPRESS(20) -#endif - -#ifdef DOSTORESTATE21 -SHA1_RECOMPRESS(21) -#endif - -#ifdef DOSTORESTATE22 -SHA1_RECOMPRESS(22) -#endif - -#ifdef DOSTORESTATE23 -SHA1_RECOMPRESS(23) -#endif - -#ifdef DOSTORESTATE24 -SHA1_RECOMPRESS(24) -#endif - -#ifdef DOSTORESTATE25 -SHA1_RECOMPRESS(25) -#endif - -#ifdef DOSTORESTATE26 -SHA1_RECOMPRESS(26) -#endif - -#ifdef DOSTORESTATE27 -SHA1_RECOMPRESS(27) -#endif - -#ifdef DOSTORESTATE28 -SHA1_RECOMPRESS(28) -#endif - -#ifdef DOSTORESTATE29 -SHA1_RECOMPRESS(29) -#endif - -#ifdef DOSTORESTATE30 -SHA1_RECOMPRESS(30) -#endif - -#ifdef DOSTORESTATE31 -SHA1_RECOMPRESS(31) -#endif - -#ifdef DOSTORESTATE32 -SHA1_RECOMPRESS(32) -#endif - -#ifdef DOSTORESTATE33 -SHA1_RECOMPRESS(33) -#endif - -#ifdef DOSTORESTATE34 -SHA1_RECOMPRESS(34) -#endif - -#ifdef DOSTORESTATE35 -SHA1_RECOMPRESS(35) -#endif - -#ifdef DOSTORESTATE36 -SHA1_RECOMPRESS(36) -#endif - -#ifdef DOSTORESTATE37 -SHA1_RECOMPRESS(37) -#endif - -#ifdef DOSTORESTATE38 -SHA1_RECOMPRESS(38) -#endif - -#ifdef DOSTORESTATE39 -SHA1_RECOMPRESS(39) -#endif - -#ifdef DOSTORESTATE40 -SHA1_RECOMPRESS(40) -#endif - -#ifdef DOSTORESTATE41 -SHA1_RECOMPRESS(41) -#endif - -#ifdef DOSTORESTATE42 -SHA1_RECOMPRESS(42) -#endif - -#ifdef DOSTORESTATE43 -SHA1_RECOMPRESS(43) -#endif - -#ifdef DOSTORESTATE44 -SHA1_RECOMPRESS(44) -#endif - -#ifdef DOSTORESTATE45 -SHA1_RECOMPRESS(45) -#endif - -#ifdef DOSTORESTATE46 -SHA1_RECOMPRESS(46) -#endif - -#ifdef DOSTORESTATE47 -SHA1_RECOMPRESS(47) -#endif - -#ifdef DOSTORESTATE48 -SHA1_RECOMPRESS(48) -#endif - -#ifdef DOSTORESTATE49 -SHA1_RECOMPRESS(49) -#endif - -#ifdef DOSTORESTATE50 -SHA1_RECOMPRESS(50) -#endif - -#ifdef DOSTORESTATE51 -SHA1_RECOMPRESS(51) -#endif - -#ifdef DOSTORESTATE52 -SHA1_RECOMPRESS(52) -#endif - -#ifdef DOSTORESTATE53 -SHA1_RECOMPRESS(53) -#endif - -#ifdef DOSTORESTATE54 -SHA1_RECOMPRESS(54) -#endif - -#ifdef DOSTORESTATE55 -SHA1_RECOMPRESS(55) -#endif - -#ifdef DOSTORESTATE56 -SHA1_RECOMPRESS(56) -#endif - -#ifdef DOSTORESTATE57 -SHA1_RECOMPRESS(57) -#endif - -#ifdef DOSTORESTATE58 -SHA1_RECOMPRESS(58) -#endif - -#ifdef DOSTORESTATE59 -SHA1_RECOMPRESS(59) -#endif - -#ifdef DOSTORESTATE60 -SHA1_RECOMPRESS(60) -#endif - -#ifdef DOSTORESTATE61 -SHA1_RECOMPRESS(61) -#endif - -#ifdef DOSTORESTATE62 -SHA1_RECOMPRESS(62) -#endif - -#ifdef DOSTORESTATE63 -SHA1_RECOMPRESS(63) -#endif - -#ifdef DOSTORESTATE64 -SHA1_RECOMPRESS(64) -#endif - -#ifdef DOSTORESTATE65 -SHA1_RECOMPRESS(65) -#endif - -#ifdef DOSTORESTATE66 -SHA1_RECOMPRESS(66) -#endif - -#ifdef DOSTORESTATE67 -SHA1_RECOMPRESS(67) -#endif - -#ifdef DOSTORESTATE68 -SHA1_RECOMPRESS(68) -#endif - -#ifdef DOSTORESTATE69 -SHA1_RECOMPRESS(69) -#endif - -#ifdef DOSTORESTATE70 -SHA1_RECOMPRESS(70) -#endif - -#ifdef DOSTORESTATE71 -SHA1_RECOMPRESS(71) -#endif - -#ifdef DOSTORESTATE72 -SHA1_RECOMPRESS(72) -#endif - -#ifdef DOSTORESTATE73 -SHA1_RECOMPRESS(73) -#endif - -#ifdef DOSTORESTATE74 -SHA1_RECOMPRESS(74) -#endif - -#ifdef DOSTORESTATE75 -SHA1_RECOMPRESS(75) -#endif - -#ifdef DOSTORESTATE76 -SHA1_RECOMPRESS(76) -#endif - -#ifdef DOSTORESTATE77 -SHA1_RECOMPRESS(77) -#endif - -#ifdef DOSTORESTATE78 -SHA1_RECOMPRESS(78) -#endif - -#ifdef DOSTORESTATE79 -SHA1_RECOMPRESS(79) -#endif - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) -{ - switch (step) - { -#ifdef DOSTORESTATE0 - case 0: - sha1recompress_fast_0(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE1 - case 1: - sha1recompress_fast_1(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE2 - case 2: - sha1recompress_fast_2(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE3 - case 3: - sha1recompress_fast_3(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE4 - case 4: - sha1recompress_fast_4(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE5 - case 5: - sha1recompress_fast_5(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE6 - case 6: - sha1recompress_fast_6(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE7 - case 7: - sha1recompress_fast_7(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE8 - case 8: - sha1recompress_fast_8(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE9 - case 9: - sha1recompress_fast_9(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE10 - case 10: - sha1recompress_fast_10(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE11 - case 11: - sha1recompress_fast_11(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE12 - case 12: - sha1recompress_fast_12(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE13 - case 13: - sha1recompress_fast_13(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE14 - case 14: - sha1recompress_fast_14(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE15 - case 15: - sha1recompress_fast_15(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE16 - case 16: - sha1recompress_fast_16(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE17 - case 17: - sha1recompress_fast_17(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE18 - case 18: - sha1recompress_fast_18(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE19 - case 19: - sha1recompress_fast_19(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE20 - case 20: - sha1recompress_fast_20(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE21 - case 21: - sha1recompress_fast_21(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE22 - case 22: - sha1recompress_fast_22(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE23 - case 23: - sha1recompress_fast_23(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE24 - case 24: - sha1recompress_fast_24(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE25 - case 25: - sha1recompress_fast_25(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE26 - case 26: - sha1recompress_fast_26(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE27 - case 27: - sha1recompress_fast_27(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE28 - case 28: - sha1recompress_fast_28(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE29 - case 29: - sha1recompress_fast_29(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE30 - case 30: - sha1recompress_fast_30(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE31 - case 31: - sha1recompress_fast_31(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE32 - case 32: - sha1recompress_fast_32(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE33 - case 33: - sha1recompress_fast_33(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE34 - case 34: - sha1recompress_fast_34(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE35 - case 35: - sha1recompress_fast_35(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE36 - case 36: - sha1recompress_fast_36(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE37 - case 37: - sha1recompress_fast_37(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE38 - case 38: - sha1recompress_fast_38(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE39 - case 39: - sha1recompress_fast_39(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE40 - case 40: - sha1recompress_fast_40(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE41 - case 41: - sha1recompress_fast_41(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE42 - case 42: - sha1recompress_fast_42(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE43 - case 43: - sha1recompress_fast_43(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE44 - case 44: - sha1recompress_fast_44(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE45 - case 45: - sha1recompress_fast_45(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE46 - case 46: - sha1recompress_fast_46(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE47 - case 47: - sha1recompress_fast_47(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE48 - case 48: - sha1recompress_fast_48(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE49 - case 49: - sha1recompress_fast_49(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE50 - case 50: - sha1recompress_fast_50(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE51 - case 51: - sha1recompress_fast_51(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE52 - case 52: - sha1recompress_fast_52(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE53 - case 53: - sha1recompress_fast_53(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE54 - case 54: - sha1recompress_fast_54(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE55 - case 55: - sha1recompress_fast_55(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE56 - case 56: - sha1recompress_fast_56(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE57 - case 57: - sha1recompress_fast_57(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE58 - case 58: - sha1recompress_fast_58(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE59 - case 59: - sha1recompress_fast_59(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE60 - case 60: - sha1recompress_fast_60(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE61 - case 61: - sha1recompress_fast_61(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE62 - case 62: - sha1recompress_fast_62(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE63 - case 63: - sha1recompress_fast_63(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE64 - case 64: - sha1recompress_fast_64(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE65 - case 65: - sha1recompress_fast_65(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE66 - case 66: - sha1recompress_fast_66(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE67 - case 67: - sha1recompress_fast_67(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE68 - case 68: - sha1recompress_fast_68(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE69 - case 69: - sha1recompress_fast_69(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE70 - case 70: - sha1recompress_fast_70(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE71 - case 71: - sha1recompress_fast_71(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE72 - case 72: - sha1recompress_fast_72(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE73 - case 73: - sha1recompress_fast_73(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE74 - case 74: - sha1recompress_fast_74(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE75 - case 75: - sha1recompress_fast_75(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE76 - case 76: - sha1recompress_fast_76(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE77 - case 77: - sha1recompress_fast_77(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE78 - case 78: - sha1recompress_fast_78(ihvin, ihvout, me2, state); - break; -#endif -#ifdef DOSTORESTATE79 - case 79: - sha1recompress_fast_79(ihvin, ihvout, me2, state); - break; -#endif - default: - abort(); - } -} - -static void sha1_process(SHA1_CTX *ctx, const uint32_t block[16]) -{ - unsigned i, j; - uint32_t ubc_dv_mask[DVMASKSIZE] = {0xFFFFFFFF}; - uint32_t ihvtmp[5]; - - ctx->ihv1[0] = ctx->ihv[0]; - ctx->ihv1[1] = ctx->ihv[1]; - ctx->ihv1[2] = ctx->ihv[2]; - ctx->ihv1[3] = ctx->ihv[3]; - ctx->ihv1[4] = ctx->ihv[4]; - - sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states); - - if (ctx->detect_coll) - { - if (ctx->ubc_check) - { - ubc_check(ctx->m1, ubc_dv_mask); - } - - if (ubc_dv_mask[0] != 0) - { - for (i = 0; sha1_dvs[i].dvType != 0; ++i) - { - if (ubc_dv_mask[0] & ((uint32_t)(1) << sha1_dvs[i].maskb)) - { - for (j = 0; j < 80; ++j) - ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j]; - - sha1_recompression_step(sha1_dvs[i].testt, ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]); - - /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */ - if ((0 == ((ihvtmp[0] ^ ctx->ihv[0]) | (ihvtmp[1] ^ ctx->ihv[1]) | (ihvtmp[2] ^ ctx->ihv[2]) | (ihvtmp[3] ^ ctx->ihv[3]) | (ihvtmp[4] ^ ctx->ihv[4]))) || - (ctx->reduced_round_coll && 0 == ((ctx->ihv1[0] ^ ctx->ihv2[0]) | (ctx->ihv1[1] ^ ctx->ihv2[1]) | (ctx->ihv1[2] ^ ctx->ihv2[2]) | (ctx->ihv1[3] ^ ctx->ihv2[3]) | (ctx->ihv1[4] ^ ctx->ihv2[4])))) - { - ctx->found_collision = 1; - - if (ctx->safe_hash) - { - sha1_compression_W(ctx->ihv, ctx->m1); - sha1_compression_W(ctx->ihv, ctx->m1); - } - - break; - } - } - } - } - } -} - -void SHA1DCInit(SHA1_CTX *ctx) -{ - ctx->total = 0; - ctx->ihv[0] = 0x67452301; - ctx->ihv[1] = 0xEFCDAB89; - ctx->ihv[2] = 0x98BADCFE; - ctx->ihv[3] = 0x10325476; - ctx->ihv[4] = 0xC3D2E1F0; - ctx->found_collision = 0; - ctx->safe_hash = SHA1DC_INIT_SAFE_HASH_DEFAULT; - ctx->ubc_check = 1; - ctx->detect_coll = 1; - ctx->reduced_round_coll = 0; - ctx->callback = NULL; -} - -void SHA1DCSetSafeHash(SHA1_CTX *ctx, int safehash) -{ - if (safehash) - ctx->safe_hash = 1; - else - ctx->safe_hash = 0; -} - -void SHA1DCSetUseUBC(SHA1_CTX *ctx, int ubc_check) -{ - if (ubc_check) - ctx->ubc_check = 1; - else - ctx->ubc_check = 0; -} - -void SHA1DCSetUseDetectColl(SHA1_CTX *ctx, int detect_coll) -{ - if (detect_coll) - ctx->detect_coll = 1; - else - ctx->detect_coll = 0; -} - -void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *ctx, int reduced_round_coll) -{ - if (reduced_round_coll) - ctx->reduced_round_coll = 1; - else - ctx->reduced_round_coll = 0; -} - -void SHA1DCSetCallback(SHA1_CTX *ctx, collision_block_callback callback) -{ - ctx->callback = callback; -} - -void SHA1DCUpdate(SHA1_CTX *ctx, const char *buf, size_t len) -{ - unsigned left, fill; - - if (len == 0) - return; - - left = ctx->total & 63; - fill = 64 - left; - - if (left && len >= fill) - { - ctx->total += fill; - memcpy(ctx->buffer + left, buf, fill); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); - buf += fill; - len -= fill; - left = 0; - } - while (len >= 64) - { - ctx->total += 64; - -#if defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) - sha1_process(ctx, (uint32_t *)(buf)); -#else - memcpy(ctx->buffer, buf, 64); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); -#endif /* defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) */ - buf += 64; - len -= 64; - } - if (len > 0) - { - ctx->total += len; - memcpy(ctx->buffer + left, buf, len); - } -} - -static const unsigned char sha1_padding[64] = - { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx) -{ - uint32_t last = ctx->total & 63; - uint32_t padn = (last < 56) ? (56 - last) : (120 - last); - uint64_t total; - SHA1DCUpdate(ctx, (const char *)(sha1_padding), padn); - - total = ctx->total - padn; - total <<= 3; - ctx->buffer[56] = (unsigned char)(total >> 56); - ctx->buffer[57] = (unsigned char)(total >> 48); - ctx->buffer[58] = (unsigned char)(total >> 40); - ctx->buffer[59] = (unsigned char)(total >> 32); - ctx->buffer[60] = (unsigned char)(total >> 24); - ctx->buffer[61] = (unsigned char)(total >> 16); - ctx->buffer[62] = (unsigned char)(total >> 8); - ctx->buffer[63] = (unsigned char)(total); - sha1_process(ctx, (uint32_t *)(ctx->buffer)); - output[0] = (unsigned char)(ctx->ihv[0] >> 24); - output[1] = (unsigned char)(ctx->ihv[0] >> 16); - output[2] = (unsigned char)(ctx->ihv[0] >> 8); - output[3] = (unsigned char)(ctx->ihv[0]); - output[4] = (unsigned char)(ctx->ihv[1] >> 24); - output[5] = (unsigned char)(ctx->ihv[1] >> 16); - output[6] = (unsigned char)(ctx->ihv[1] >> 8); - output[7] = (unsigned char)(ctx->ihv[1]); - output[8] = (unsigned char)(ctx->ihv[2] >> 24); - output[9] = (unsigned char)(ctx->ihv[2] >> 16); - output[10] = (unsigned char)(ctx->ihv[2] >> 8); - output[11] = (unsigned char)(ctx->ihv[2]); - output[12] = (unsigned char)(ctx->ihv[3] >> 24); - output[13] = (unsigned char)(ctx->ihv[3] >> 16); - output[14] = (unsigned char)(ctx->ihv[3] >> 8); - output[15] = (unsigned char)(ctx->ihv[3]); - output[16] = (unsigned char)(ctx->ihv[4] >> 24); - output[17] = (unsigned char)(ctx->ihv[4] >> 16); - output[18] = (unsigned char)(ctx->ihv[4] >> 8); - output[19] = (unsigned char)(ctx->ihv[4]); - return ctx->found_collision; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h b/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h deleted file mode 100644 index ce4942f617..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/sha1.h +++ /dev/null @@ -1,114 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -#ifndef SHA1DC_SHA1_H -#define SHA1DC_SHA1_H - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - - /* sha-1 compression function that takes an already expanded message, and additionally store intermediate states */ - /* only stores states ii (the state between step ii-1 and step ii) when DOSTORESTATEii is defined in ubc_check.h */ - void sha1_compression_states(uint32_t[5], const uint32_t[16], uint32_t[80], uint32_t[80][5]); - - /* - // Function type for sha1_recompression_step_T (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]). - // Where 0 <= T < 80 - // me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference.) - // state is the internal state (a,b,c,d,e) before step T of the SHA-1 compression function while processing the original message block. - // The function will return: - // ihvin: The reconstructed input chaining value. - // ihvout: The reconstructed output chaining value. - */ - typedef void (*sha1_recompression_type)(uint32_t *, uint32_t *, const uint32_t *, const uint32_t *); - - /* A callback function type that can be set to be called when a collision block has been found: */ - /* void collision_block_callback(uint64_t byteoffset, const uint32_t ihvin1[5], const uint32_t ihvin2[5], const uint32_t m1[80], const uint32_t m2[80]) */ - typedef void (*collision_block_callback)(uint64_t, const uint32_t *, const uint32_t *, const uint32_t *, const uint32_t *); - - /* The SHA-1 context. */ - typedef struct - { - uint64_t total; - uint32_t ihv[5]; - unsigned char buffer[64]; - int found_collision; - int safe_hash; - int detect_coll; - int ubc_check; - int reduced_round_coll; - collision_block_callback callback; - - uint32_t ihv1[5]; - uint32_t ihv2[5]; - uint32_t m1[80]; - uint32_t m2[80]; - uint32_t states[80][5]; - } SHA1_CTX; - - /* Initialize SHA-1 context. */ - void SHA1DCInit(SHA1_CTX *); - - /* - Function to enable safe SHA-1 hashing: - Collision attacks are thwarted by hashing a detected near-collision block 3 times. - Think of it as extending SHA-1 from 80-steps to 240-steps for such blocks: - The best collision attacks against SHA-1 have complexity about 2^60, - thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would be 2^180. - An attacker would be better off using a generic birthday search of complexity 2^80. - - Enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected, - but it will result in a different SHA-1 hash for messages where a collision attack was detected. - This will automatically invalidate SHA-1 based digital signature forgeries. - Enabled by default. - */ - void SHA1DCSetSafeHash(SHA1_CTX *, int); - - /* - Function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up). - Enabled by default - */ - void SHA1DCSetUseUBC(SHA1_CTX *, int); - - /* - Function to disable or enable the use of Collision Detection. - Enabled by default. - */ - void SHA1DCSetUseDetectColl(SHA1_CTX *, int); - - /* function to disable or enable the detection of reduced-round SHA-1 collisions */ - /* disabled by default */ - void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX *, int); - - /* function to set a callback function, pass NULL to disable */ - /* by default no callback set */ - void SHA1DCSetCallback(SHA1_CTX *, collision_block_callback); - - /* update SHA-1 context with buffer contents */ - void SHA1DCUpdate(SHA1_CTX *, const char *, size_t); - - /* obtain SHA-1 hash from SHA-1 context */ - /* returns: 0 = no collision detected, otherwise = collision found => warn user for active attack */ - int SHA1DCFinal(unsigned char[20], SHA1_CTX *); - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H -#endif - -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c b/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c deleted file mode 100644 index b3d58ce282..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.c +++ /dev/null @@ -1,297 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -// -// ubc_check is programmatically generated and the unavoidable bitconditions have been hardcoded -// a directly verifiable version named ubc_check_verify can be found in ubc_check_verify.c -// ubc_check has been verified against ubc_check_verify using the 'ubc_check_test' program in the tools section -*/ - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif -#ifdef SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C -#endif -#include "ubc_check.h" - -static const uint32_t DV_I_43_0_bit = (uint32_t)(1) << 0; -static const uint32_t DV_I_44_0_bit = (uint32_t)(1) << 1; -static const uint32_t DV_I_45_0_bit = (uint32_t)(1) << 2; -static const uint32_t DV_I_46_0_bit = (uint32_t)(1) << 3; -static const uint32_t DV_I_46_2_bit = (uint32_t)(1) << 4; -static const uint32_t DV_I_47_0_bit = (uint32_t)(1) << 5; -static const uint32_t DV_I_47_2_bit = (uint32_t)(1) << 6; -static const uint32_t DV_I_48_0_bit = (uint32_t)(1) << 7; -static const uint32_t DV_I_48_2_bit = (uint32_t)(1) << 8; -static const uint32_t DV_I_49_0_bit = (uint32_t)(1) << 9; -static const uint32_t DV_I_49_2_bit = (uint32_t)(1) << 10; -static const uint32_t DV_I_50_0_bit = (uint32_t)(1) << 11; -static const uint32_t DV_I_50_2_bit = (uint32_t)(1) << 12; -static const uint32_t DV_I_51_0_bit = (uint32_t)(1) << 13; -static const uint32_t DV_I_51_2_bit = (uint32_t)(1) << 14; -static const uint32_t DV_I_52_0_bit = (uint32_t)(1) << 15; -static const uint32_t DV_II_45_0_bit = (uint32_t)(1) << 16; -static const uint32_t DV_II_46_0_bit = (uint32_t)(1) << 17; -static const uint32_t DV_II_46_2_bit = (uint32_t)(1) << 18; -static const uint32_t DV_II_47_0_bit = (uint32_t)(1) << 19; -static const uint32_t DV_II_48_0_bit = (uint32_t)(1) << 20; -static const uint32_t DV_II_49_0_bit = (uint32_t)(1) << 21; -static const uint32_t DV_II_49_2_bit = (uint32_t)(1) << 22; -static const uint32_t DV_II_50_0_bit = (uint32_t)(1) << 23; -static const uint32_t DV_II_50_2_bit = (uint32_t)(1) << 24; -static const uint32_t DV_II_51_0_bit = (uint32_t)(1) << 25; -static const uint32_t DV_II_51_2_bit = (uint32_t)(1) << 26; -static const uint32_t DV_II_52_0_bit = (uint32_t)(1) << 27; -static const uint32_t DV_II_53_0_bit = (uint32_t)(1) << 28; -static const uint32_t DV_II_54_0_bit = (uint32_t)(1) << 29; -static const uint32_t DV_II_55_0_bit = (uint32_t)(1) << 30; -static const uint32_t DV_II_56_0_bit = (uint32_t)(1) << 31; - -dv_info_t sha1_dvs[] = - { - {1, 43, 0, 58, 0, 0, {0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803, 0x80000161, 0x80000599}}, {1, 44, 0, 58, 0, 1, {0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803, 0x80000161}}, {1, 45, 0, 58, 0, 2, {0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c, 0x00000803}}, {1, 46, 0, 58, 0, 3, {0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6, 0x8000004c}}, {1, 46, 2, 58, 0, 4, {0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020, 0x0000039a, 0x00000132}}, {1, 47, 0, 58, 0, 5, {0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408, 0x800000e6}}, {1, 47, 2, 58, 0, 6, {0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020, 0x0000039a}}, {1, 48, 0, 58, 0, 7, {0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164, 0x00000408}}, {1, 48, 2, 58, 0, 8, {0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590, 0x00001020}}, {1, 49, 0, 58, 0, 9, {0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018, 0x00000164}}, {1, 49, 2, 58, 0, 10, {0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060, 0x00000590}}, {1, 50, 0, 65, 0, 11, {0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202, 0x00000018}}, {1, 50, 2, 65, 0, 12, {0x20000030, 0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a, 0x00000060}}, {1, 51, 0, 65, 0, 13, {0xe8000000, 0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012, 0x80000202}}, {1, 51, 2, 65, 0, 14, {0xa0000003, 0x20000030, 0x60000000, 0xe000002a, 0x20000043, 0xb0000040, 0xd0000053, 0xd0000022, 0x20000000, 0x60000032, 0x60000043, 0x20000040, 0xe0000042, 0x60000002, 0x80000001, 0x00000020, 0x00000003, 0x40000052, 0x40000040, 0xe0000052, 0xa0000000, 0x80000040, 0x20000001, 0x20000060, 0x80000001, 0x40000042, 0xc0000043, 0x40000022, 0x00000003, 0x40000042, 0xc0000043, 0xc0000022, 0x00000001, 0x40000002, 0xc0000043, 0x40000062, 0x80000001, 0x40000042, 0x40000042, 0x40000002, 0x00000002, 0x00000040, 0x80000002, 0x80000000, 0x80000002, 0x80000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000000, 0x00000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000101, 0x00000009, 0x00000012, 0x00000202, 0x0000001a, 0x00000124, 0x0000040c, 0x00000026, 0x0000004a, 0x0000080a}}, {1, 52, 0, 65, 0, 15, {0x04000010, 0xe8000000, 0x0800000c, 0x18000000, 0xb800000a, 0xc8000010, 0x2c000010, 0xf4000014, 0xb4000008, 0x08000000, 0x9800000c, 0xd8000010, 0x08000010, 0xb8000010, 0x98000000, 0x60000000, 0x00000008, 0xc0000000, 0x90000014, 0x10000010, 0xb8000014, 0x28000000, 0x20000010, 0x48000000, 0x08000018, 0x60000000, 0x90000010, 0xf0000010, 0x90000008, 0xc0000000, 0x90000010, 0xf0000010, 0xb0000008, 0x40000000, 0x90000000, 0xf0000010, 0x90000018, 0x60000000, 0x90000010, 0x90000010, 0x90000000, 0x80000000, 0x00000010, 0xa0000000, 0x20000000, 0xa0000000, 0x20000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x20000000, 0x00000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000040, 0x40000002, 0x80000004, 0x80000080, 0x80000006, 0x00000049, 0x00000103, 0x80000009, 0x80000012}}, {2, 45, 0, 58, 0, 16, {0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4, 0x80000054, 0x00000967}}, {2, 46, 0, 58, 0, 17, {0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4, 0x80000054}}, {2, 46, 2, 58, 0, 18, {0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c, 0x000005b6, 0x0000106a, 0x00000b90, 0x00000152}}, {2, 47, 0, 58, 0, 19, {0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a, 0x000002e4}}, {2, 48, 0, 58, 0, 20, {0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d, 0x8000041a}}, {2, 49, 0, 58, 0, 21, {0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b, 0x8000016d}}, {2, 49, 2, 58, 0, 22, {0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c, 0x000005b6}}, {2, 50, 0, 65, 0, 23, {0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b, 0x0000011b}}, {2, 50, 2, 65, 0, 24, {0xd0000072, 0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e, 0x0000046c}}, {2, 51, 0, 65, 0, 25, {0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014, 0x8000024b}}, {2, 51, 2, 65, 0, 26, {0x00000043, 0xd0000072, 0xf0000010, 0xf000006a, 0x80000040, 0x90000070, 0xb0000053, 0x30000008, 0x00000043, 0xd0000072, 0xb0000010, 0xf0000062, 0xc0000042, 0x00000030, 0xe0000042, 0x20000060, 0xe0000041, 0x20000050, 0xc0000041, 0xe0000072, 0xa0000003, 0xc0000012, 0x60000041, 0xc0000032, 0x20000001, 0xc0000002, 0xe0000042, 0x60000042, 0x80000002, 0x00000000, 0x00000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000000, 0x00000040, 0x80000001, 0x00000060, 0x80000003, 0x40000002, 0xc0000040, 0xc0000002, 0x80000000, 0x80000000, 0x80000002, 0x00000040, 0x00000002, 0x80000000, 0x80000000, 0x80000000, 0x00000002, 0x00000040, 0x00000000, 0x80000040, 0x80000002, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000080, 0x00000004, 0x00000009, 0x00000105, 0x00000089, 0x00000016, 0x0000020b, 0x0000011b, 0x0000012d, 0x0000041e, 0x00000224, 0x00000050, 0x0000092e}}, {2, 52, 0, 65, 0, 27, {0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089, 0x00000014}}, {2, 53, 0, 65, 0, 28, {0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107, 0x00000089}}, {2, 54, 0, 65, 0, 29, {0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b, 0x80000107}}, {2, 55, 0, 65, 0, 30, {0x00000010, 0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046, 0x4000004b}}, {2, 56, 0, 65, 0, 31, {0x2600001a, 0x00000010, 0x0400001c, 0xcc000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x3c000004, 0xbc00001a, 0x20000010, 0x2400001c, 0xec000014, 0x0c000002, 0xc0000010, 0xb400001c, 0x2c000004, 0xbc000018, 0xb0000010, 0x0000000c, 0xb8000010, 0x08000018, 0x78000010, 0x08000014, 0x70000010, 0xb800001c, 0xe8000000, 0xb0000004, 0x58000010, 0xb000000c, 0x48000000, 0xb0000000, 0xb8000010, 0x98000010, 0xa0000000, 0x00000000, 0x00000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0x20000000, 0x00000010, 0x60000000, 0x00000018, 0xe0000000, 0x90000000, 0x30000010, 0xb0000000, 0x20000000, 0x20000000, 0xa0000000, 0x00000010, 0x80000000, 0x20000000, 0x20000000, 0x20000000, 0x80000000, 0x00000010, 0x00000000, 0x20000010, 0xa0000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000020, 0x00000001, 0x40000002, 0x40000041, 0x40000022, 0x80000005, 0xc0000082, 0xc0000046}}, {0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}; -void ubc_check(const uint32_t W[80], uint32_t dvmask[1]) -{ - uint32_t mask = ~((uint32_t)(0)); - mask &= (((((W[44] ^ W[45]) >> 29) & 1) - 1) | ~(DV_I_48_0_bit | DV_I_51_0_bit | DV_I_52_0_bit | DV_II_45_0_bit | DV_II_46_0_bit | DV_II_50_0_bit | DV_II_51_0_bit)); - mask &= (((((W[49] ^ W[50]) >> 29) & 1) - 1) | ~(DV_I_46_0_bit | DV_II_45_0_bit | DV_II_50_0_bit | DV_II_51_0_bit | DV_II_55_0_bit | DV_II_56_0_bit)); - mask &= (((((W[48] ^ W[49]) >> 29) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_52_0_bit | DV_II_49_0_bit | DV_II_50_0_bit | DV_II_54_0_bit | DV_II_55_0_bit)); - mask &= ((((W[47] ^ (W[50] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)); - mask &= (((((W[47] ^ W[48]) >> 29) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_51_0_bit | DV_II_48_0_bit | DV_II_49_0_bit | DV_II_53_0_bit | DV_II_54_0_bit)); - mask &= (((((W[46] >> 4) ^ (W[49] >> 29)) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit | DV_II_50_0_bit | DV_II_55_0_bit)); - mask &= (((((W[46] ^ W[47]) >> 29) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_50_0_bit | DV_II_47_0_bit | DV_II_48_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)); - mask &= (((((W[45] >> 4) ^ (W[48] >> 29)) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit | DV_II_49_0_bit | DV_II_54_0_bit)); - mask &= (((((W[45] ^ W[46]) >> 29) & 1) - 1) | ~(DV_I_49_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_47_0_bit | DV_II_51_0_bit | DV_II_52_0_bit)); - mask &= (((((W[44] >> 4) ^ (W[47] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit | DV_II_48_0_bit | DV_II_53_0_bit)); - mask &= (((((W[43] >> 4) ^ (W[46] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit | DV_II_47_0_bit | DV_II_52_0_bit)); - mask &= (((((W[43] ^ W[44]) >> 29) & 1) - 1) | ~(DV_I_47_0_bit | DV_I_50_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_49_0_bit | DV_II_50_0_bit)); - mask &= (((((W[42] >> 4) ^ (W[45] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_51_0_bit)); - mask &= (((((W[41] >> 4) ^ (W[44] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_50_0_bit)); - mask &= (((((W[40] ^ W[41]) >> 29) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_47_0_bit | DV_I_48_0_bit | DV_II_46_0_bit | DV_II_47_0_bit | DV_II_56_0_bit)); - mask &= (((((W[54] ^ W[55]) >> 29) & 1) - 1) | ~(DV_I_51_0_bit | DV_II_47_0_bit | DV_II_50_0_bit | DV_II_55_0_bit | DV_II_56_0_bit)); - mask &= (((((W[53] ^ W[54]) >> 29) & 1) - 1) | ~(DV_I_50_0_bit | DV_II_46_0_bit | DV_II_49_0_bit | DV_II_54_0_bit | DV_II_55_0_bit)); - mask &= (((((W[52] ^ W[53]) >> 29) & 1) - 1) | ~(DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit | DV_II_53_0_bit | DV_II_54_0_bit)); - mask &= ((((W[50] ^ (W[53] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_50_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_48_0_bit | DV_II_54_0_bit)); - mask &= (((((W[50] ^ W[51]) >> 29) & 1) - 1) | ~(DV_I_47_0_bit | DV_II_46_0_bit | DV_II_51_0_bit | DV_II_52_0_bit | DV_II_56_0_bit)); - mask &= ((((W[49] ^ (W[52] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit | DV_II_47_0_bit | DV_II_53_0_bit)); - mask &= ((((W[48] ^ (W[51] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit | DV_II_46_0_bit | DV_II_52_0_bit)); - mask &= (((((W[42] ^ W[43]) >> 29) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_49_0_bit | DV_I_50_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)); - mask &= (((((W[41] ^ W[42]) >> 29) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_48_0_bit | DV_I_49_0_bit | DV_II_47_0_bit | DV_II_48_0_bit)); - mask &= (((((W[40] >> 4) ^ (W[43] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_50_0_bit | DV_II_49_0_bit | DV_II_56_0_bit)); - mask &= (((((W[39] >> 4) ^ (W[42] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_49_0_bit | DV_II_48_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit | DV_I_48_0_bit | DV_II_47_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)) - mask &= (((((W[38] >> 4) ^ (W[41] >> 29)) & 1) - 1) | ~(DV_I_44_0_bit | DV_I_48_0_bit | DV_II_47_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)); - mask &= (((((W[37] >> 4) ^ (W[40] >> 29)) & 1) - 1) | ~(DV_I_43_0_bit | DV_I_47_0_bit | DV_II_46_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)) - mask &= (((((W[55] ^ W[56]) >> 29) & 1) - 1) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_51_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_50_0_bit | DV_II_56_0_bit)) - mask &= ((((W[52] ^ (W[55] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_50_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_51_0_bit | DV_II_47_0_bit | DV_II_49_0_bit | DV_II_55_0_bit)) - mask &= ((((W[51] ^ (W[54] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_51_0_bit | DV_II_47_0_bit | DV_II_49_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_48_0_bit | DV_II_47_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)) - mask &= (((((W[51] ^ W[52]) >> 29) & 1) - 1) | ~(DV_I_48_0_bit | DV_II_47_0_bit | DV_II_52_0_bit | DV_II_53_0_bit)); - if (mask & (DV_I_46_0_bit | DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit)) - mask &= (((((W[36] >> 4) ^ (W[40] >> 29)) & 1) - 1) | ~(DV_I_46_0_bit | DV_I_49_0_bit | DV_II_45_0_bit | DV_II_48_0_bit)); - if (mask & (DV_I_52_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)) - mask &= ((0 - (((W[53] ^ W[56]) >> 29) & 1)) | ~(DV_I_52_0_bit | DV_II_48_0_bit | DV_II_49_0_bit)); - if (mask & (DV_I_50_0_bit | DV_II_46_0_bit | DV_II_47_0_bit)) - mask &= ((0 - (((W[51] ^ W[54]) >> 29) & 1)) | ~(DV_I_50_0_bit | DV_II_46_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit)) - mask &= ((0 - (((W[50] ^ W[52]) >> 29) & 1)) | ~(DV_I_49_0_bit | DV_I_51_0_bit | DV_II_45_0_bit)); - if (mask & (DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit)) - mask &= ((0 - (((W[49] ^ W[51]) >> 29) & 1)) | ~(DV_I_48_0_bit | DV_I_50_0_bit | DV_I_52_0_bit)); - if (mask & (DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit)) - mask &= ((0 - (((W[48] ^ W[50]) >> 29) & 1)) | ~(DV_I_47_0_bit | DV_I_49_0_bit | DV_I_51_0_bit)); - if (mask & (DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit)) - mask &= ((0 - (((W[47] ^ W[49]) >> 29) & 1)) | ~(DV_I_46_0_bit | DV_I_48_0_bit | DV_I_50_0_bit)); - if (mask & (DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit)) - mask &= ((0 - (((W[46] ^ W[48]) >> 29) & 1)) | ~(DV_I_45_0_bit | DV_I_47_0_bit | DV_I_49_0_bit)); - mask &= ((((W[45] ^ W[47]) & (1 << 6)) - (1 << 6)) | ~(DV_I_47_2_bit | DV_I_49_2_bit | DV_I_51_2_bit)); - if (mask & (DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit)) - mask &= ((0 - (((W[45] ^ W[47]) >> 29) & 1)) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_I_48_0_bit)); - mask &= (((((W[44] ^ W[46]) >> 6) & 1) - 1) | ~(DV_I_46_2_bit | DV_I_48_2_bit | DV_I_50_2_bit)); - if (mask & (DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit)) - mask &= ((0 - (((W[44] ^ W[46]) >> 29) & 1)) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_I_47_0_bit)); - mask &= ((0 - ((W[41] ^ (W[42] >> 5)) & (1 << 1))) | ~(DV_I_48_2_bit | DV_II_46_2_bit | DV_II_51_2_bit)); - mask &= ((0 - ((W[40] ^ (W[41] >> 5)) & (1 << 1))) | ~(DV_I_47_2_bit | DV_I_51_2_bit | DV_II_50_2_bit)); - if (mask & (DV_I_44_0_bit | DV_I_46_0_bit | DV_II_56_0_bit)) - mask &= ((0 - (((W[40] ^ W[42]) >> 4) & 1)) | ~(DV_I_44_0_bit | DV_I_46_0_bit | DV_II_56_0_bit)); - mask &= ((0 - ((W[39] ^ (W[40] >> 5)) & (1 << 1))) | ~(DV_I_46_2_bit | DV_I_50_2_bit | DV_II_49_2_bit)); - if (mask & (DV_I_43_0_bit | DV_I_45_0_bit | DV_II_55_0_bit)) - mask &= ((0 - (((W[39] ^ W[41]) >> 4) & 1)) | ~(DV_I_43_0_bit | DV_I_45_0_bit | DV_II_55_0_bit)); - if (mask & (DV_I_44_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)) - mask &= ((0 - (((W[38] ^ W[40]) >> 4) & 1)) | ~(DV_I_44_0_bit | DV_II_54_0_bit | DV_II_56_0_bit)); - if (mask & (DV_I_43_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)) - mask &= ((0 - (((W[37] ^ W[39]) >> 4) & 1)) | ~(DV_I_43_0_bit | DV_II_53_0_bit | DV_II_55_0_bit)); - mask &= ((0 - ((W[36] ^ (W[37] >> 5)) & (1 << 1))) | ~(DV_I_47_2_bit | DV_I_50_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit | DV_I_48_0_bit | DV_II_47_0_bit)) - mask &= (((((W[35] >> 4) ^ (W[39] >> 29)) & 1) - 1) | ~(DV_I_45_0_bit | DV_I_48_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_48_0_bit | DV_II_48_0_bit)) - mask &= ((0 - ((W[63] ^ (W[64] >> 5)) & (1 << 0))) | ~(DV_I_48_0_bit | DV_II_48_0_bit)); - if (mask & (DV_I_45_0_bit | DV_II_45_0_bit)) - mask &= ((0 - ((W[63] ^ (W[64] >> 5)) & (1 << 1))) | ~(DV_I_45_0_bit | DV_II_45_0_bit)); - if (mask & (DV_I_47_0_bit | DV_II_47_0_bit)) - mask &= ((0 - ((W[62] ^ (W[63] >> 5)) & (1 << 0))) | ~(DV_I_47_0_bit | DV_II_47_0_bit)); - if (mask & (DV_I_46_0_bit | DV_II_46_0_bit)) - mask &= ((0 - ((W[61] ^ (W[62] >> 5)) & (1 << 0))) | ~(DV_I_46_0_bit | DV_II_46_0_bit)); - mask &= ((0 - ((W[61] ^ (W[62] >> 5)) & (1 << 2))) | ~(DV_I_46_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_45_0_bit | DV_II_45_0_bit)) - mask &= ((0 - ((W[60] ^ (W[61] >> 5)) & (1 << 0))) | ~(DV_I_45_0_bit | DV_II_45_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_54_0_bit)) - mask &= (((((W[58] ^ W[59]) >> 29) & 1) - 1) | ~(DV_II_51_0_bit | DV_II_54_0_bit)); - if (mask & (DV_II_50_0_bit | DV_II_53_0_bit)) - mask &= (((((W[57] ^ W[58]) >> 29) & 1) - 1) | ~(DV_II_50_0_bit | DV_II_53_0_bit)); - if (mask & (DV_II_52_0_bit | DV_II_54_0_bit)) - mask &= ((((W[56] ^ (W[59] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_52_0_bit | DV_II_54_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_52_0_bit)) - mask &= ((0 - (((W[56] ^ W[59]) >> 29) & 1)) | ~(DV_II_51_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit | DV_II_52_0_bit)) - mask &= (((((W[56] ^ W[57]) >> 29) & 1) - 1) | ~(DV_II_49_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_51_0_bit | DV_II_53_0_bit)) - mask &= ((((W[55] ^ (W[58] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_51_0_bit | DV_II_53_0_bit)); - if (mask & (DV_II_50_0_bit | DV_II_52_0_bit)) - mask &= ((((W[54] ^ (W[57] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_50_0_bit | DV_II_52_0_bit)); - if (mask & (DV_II_49_0_bit | DV_II_51_0_bit)) - mask &= ((((W[53] ^ (W[56] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_II_49_0_bit | DV_II_51_0_bit)); - mask &= ((((W[51] ^ (W[50] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_50_2_bit | DV_II_46_2_bit)); - mask &= ((((W[48] ^ W[50]) & (1 << 6)) - (1 << 6)) | ~(DV_I_50_2_bit | DV_II_46_2_bit)); - if (mask & (DV_I_51_0_bit | DV_I_52_0_bit)) - mask &= ((0 - (((W[48] ^ W[55]) >> 29) & 1)) | ~(DV_I_51_0_bit | DV_I_52_0_bit)); - mask &= ((((W[47] ^ W[49]) & (1 << 6)) - (1 << 6)) | ~(DV_I_49_2_bit | DV_I_51_2_bit)); - mask &= ((((W[48] ^ (W[47] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_47_2_bit | DV_II_51_2_bit)); - mask &= ((((W[46] ^ W[48]) & (1 << 6)) - (1 << 6)) | ~(DV_I_48_2_bit | DV_I_50_2_bit)); - mask &= ((((W[47] ^ (W[46] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_46_2_bit | DV_II_50_2_bit)); - mask &= ((0 - ((W[44] ^ (W[45] >> 5)) & (1 << 1))) | ~(DV_I_51_2_bit | DV_II_49_2_bit)); - mask &= ((((W[43] ^ W[45]) & (1 << 6)) - (1 << 6)) | ~(DV_I_47_2_bit | DV_I_49_2_bit)); - mask &= (((((W[42] ^ W[44]) >> 6) & 1) - 1) | ~(DV_I_46_2_bit | DV_I_48_2_bit)); - mask &= ((((W[43] ^ (W[42] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_II_46_2_bit | DV_II_51_2_bit)); - mask &= ((((W[42] ^ (W[41] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_51_2_bit | DV_II_50_2_bit)); - mask &= ((((W[41] ^ (W[40] >> 5)) & (1 << 1)) - (1 << 1)) | ~(DV_I_50_2_bit | DV_II_49_2_bit)); - if (mask & (DV_I_52_0_bit | DV_II_51_0_bit)) - mask &= ((((W[39] ^ (W[43] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_52_0_bit | DV_II_51_0_bit)); - if (mask & (DV_I_51_0_bit | DV_II_50_0_bit)) - mask &= ((((W[38] ^ (W[42] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_51_0_bit | DV_II_50_0_bit)); - if (mask & (DV_I_48_2_bit | DV_I_51_2_bit)) - mask &= ((0 - ((W[37] ^ (W[38] >> 5)) & (1 << 1))) | ~(DV_I_48_2_bit | DV_I_51_2_bit)); - if (mask & (DV_I_50_0_bit | DV_II_49_0_bit)) - mask &= ((((W[37] ^ (W[41] >> 25)) & (1 << 4)) - (1 << 4)) | ~(DV_I_50_0_bit | DV_II_49_0_bit)); - if (mask & (DV_II_52_0_bit | DV_II_54_0_bit)) - mask &= ((0 - ((W[36] ^ W[38]) & (1 << 4))) | ~(DV_II_52_0_bit | DV_II_54_0_bit)); - mask &= ((0 - ((W[35] ^ (W[36] >> 5)) & (1 << 1))) | ~(DV_I_46_2_bit | DV_I_49_2_bit)); - if (mask & (DV_I_51_0_bit | DV_II_47_0_bit)) - mask &= ((((W[35] ^ (W[39] >> 25)) & (1 << 3)) - (1 << 3)) | ~(DV_I_51_0_bit | DV_II_47_0_bit)); - if (mask) - { - - if (mask & DV_I_43_0_bit) - if ( - !((W[61] ^ (W[62] >> 5)) & (1 << 1)) || !(!((W[59] ^ (W[63] >> 25)) & (1 << 5))) || !((W[58] ^ (W[63] >> 30)) & (1 << 0))) - mask &= ~DV_I_43_0_bit; - if (mask & DV_I_44_0_bit) - if ( - !((W[62] ^ (W[63] >> 5)) & (1 << 1)) || !(!((W[60] ^ (W[64] >> 25)) & (1 << 5))) || !((W[59] ^ (W[64] >> 30)) & (1 << 0))) - mask &= ~DV_I_44_0_bit; - if (mask & DV_I_46_2_bit) - mask &= ((~((W[40] ^ W[42]) >> 2)) | ~DV_I_46_2_bit); - if (mask & DV_I_47_2_bit) - if ( - !((W[62] ^ (W[63] >> 5)) & (1 << 2)) || !(!((W[41] ^ W[43]) & (1 << 6)))) - mask &= ~DV_I_47_2_bit; - if (mask & DV_I_48_2_bit) - if ( - !((W[63] ^ (W[64] >> 5)) & (1 << 2)) || !(!((W[48] ^ (W[49] << 5)) & (1 << 6)))) - mask &= ~DV_I_48_2_bit; - if (mask & DV_I_49_2_bit) - if ( - !(!((W[49] ^ (W[50] << 5)) & (1 << 6))) || !((W[42] ^ W[50]) & (1 << 1)) || !(!((W[39] ^ (W[40] << 5)) & (1 << 6))) || !((W[38] ^ W[40]) & (1 << 1))) - mask &= ~DV_I_49_2_bit; - if (mask & DV_I_50_0_bit) - mask &= ((((W[36] ^ W[37]) << 7)) | ~DV_I_50_0_bit); - if (mask & DV_I_50_2_bit) - mask &= ((((W[43] ^ W[51]) << 11)) | ~DV_I_50_2_bit); - if (mask & DV_I_51_0_bit) - mask &= ((((W[37] ^ W[38]) << 9)) | ~DV_I_51_0_bit); - if (mask & DV_I_51_2_bit) - if ( - !(!((W[51] ^ (W[52] << 5)) & (1 << 6))) || !(!((W[49] ^ W[51]) & (1 << 6))) || !(!((W[37] ^ (W[37] >> 5)) & (1 << 1))) || !(!((W[35] ^ (W[39] >> 25)) & (1 << 5)))) - mask &= ~DV_I_51_2_bit; - if (mask & DV_I_52_0_bit) - mask &= ((((W[38] ^ W[39]) << 11)) | ~DV_I_52_0_bit); - if (mask & DV_II_46_2_bit) - mask &= ((((W[47] ^ W[51]) << 17)) | ~DV_II_46_2_bit); - if (mask & DV_II_48_0_bit) - if ( - !(!((W[36] ^ (W[40] >> 25)) & (1 << 3))) || !((W[35] ^ (W[40] << 2)) & (1 << 30))) - mask &= ~DV_II_48_0_bit; - if (mask & DV_II_49_0_bit) - if ( - !(!((W[37] ^ (W[41] >> 25)) & (1 << 3))) || !((W[36] ^ (W[41] << 2)) & (1 << 30))) - mask &= ~DV_II_49_0_bit; - if (mask & DV_II_49_2_bit) - if ( - !(!((W[53] ^ (W[54] << 5)) & (1 << 6))) || !(!((W[51] ^ W[53]) & (1 << 6))) || !((W[50] ^ W[54]) & (1 << 1)) || !(!((W[45] ^ (W[46] << 5)) & (1 << 6))) || !(!((W[37] ^ (W[41] >> 25)) & (1 << 5))) || !((W[36] ^ (W[41] >> 30)) & (1 << 0))) - mask &= ~DV_II_49_2_bit; - if (mask & DV_II_50_0_bit) - if ( - !((W[55] ^ W[58]) & (1 << 29)) || !(!((W[38] ^ (W[42] >> 25)) & (1 << 3))) || !((W[37] ^ (W[42] << 2)) & (1 << 30))) - mask &= ~DV_II_50_0_bit; - if (mask & DV_II_50_2_bit) - if ( - !(!((W[54] ^ (W[55] << 5)) & (1 << 6))) || !(!((W[52] ^ W[54]) & (1 << 6))) || !((W[51] ^ W[55]) & (1 << 1)) || !((W[45] ^ W[47]) & (1 << 1)) || !(!((W[38] ^ (W[42] >> 25)) & (1 << 5))) || !((W[37] ^ (W[42] >> 30)) & (1 << 0))) - mask &= ~DV_II_50_2_bit; - if (mask & DV_II_51_0_bit) - if ( - !(!((W[39] ^ (W[43] >> 25)) & (1 << 3))) || !((W[38] ^ (W[43] << 2)) & (1 << 30))) - mask &= ~DV_II_51_0_bit; - if (mask & DV_II_51_2_bit) - if ( - !(!((W[55] ^ (W[56] << 5)) & (1 << 6))) || !(!((W[53] ^ W[55]) & (1 << 6))) || !((W[52] ^ W[56]) & (1 << 1)) || !((W[46] ^ W[48]) & (1 << 1)) || !(!((W[39] ^ (W[43] >> 25)) & (1 << 5))) || !((W[38] ^ (W[43] >> 30)) & (1 << 0))) - mask &= ~DV_II_51_2_bit; - if (mask & DV_II_52_0_bit) - if ( - !(!((W[59] ^ W[60]) & (1 << 29))) || !(!((W[40] ^ (W[44] >> 25)) & (1 << 3))) || !(!((W[40] ^ (W[44] >> 25)) & (1 << 4))) || !((W[39] ^ (W[44] << 2)) & (1 << 30))) - mask &= ~DV_II_52_0_bit; - if (mask & DV_II_53_0_bit) - if ( - !((W[58] ^ W[61]) & (1 << 29)) || !(!((W[57] ^ (W[61] >> 25)) & (1 << 4))) || !(!((W[41] ^ (W[45] >> 25)) & (1 << 3))) || !(!((W[41] ^ (W[45] >> 25)) & (1 << 4)))) - mask &= ~DV_II_53_0_bit; - if (mask & DV_II_54_0_bit) - if ( - !(!((W[58] ^ (W[62] >> 25)) & (1 << 4))) || !(!((W[42] ^ (W[46] >> 25)) & (1 << 3))) || !(!((W[42] ^ (W[46] >> 25)) & (1 << 4)))) - mask &= ~DV_II_54_0_bit; - if (mask & DV_II_55_0_bit) - if ( - !(!((W[59] ^ (W[63] >> 25)) & (1 << 4))) || !(!((W[57] ^ (W[59] >> 25)) & (1 << 4))) || !(!((W[43] ^ (W[47] >> 25)) & (1 << 3))) || !(!((W[43] ^ (W[47] >> 25)) & (1 << 4)))) - mask &= ~DV_II_55_0_bit; - if (mask & DV_II_56_0_bit) - if ( - !(!((W[60] ^ (W[64] >> 25)) & (1 << 4))) || !(!((W[44] ^ (W[48] >> 25)) & (1 << 3))) || !(!((W[44] ^ (W[48] >> 25)) & (1 << 4)))) - mask &= ~DV_II_56_0_bit; - } - - dvmask[0] = mask; -} - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_C -#endif diff --git a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h b/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h deleted file mode 100644 index a8863faf46..0000000000 --- a/vendor/github.com/pjbgf/sha1cd/cgo/ubc_check.h +++ /dev/null @@ -1,64 +0,0 @@ -/*** - * Copyright 2017 Marc Stevens , Dan Shumow - * Distributed under the MIT Software License. - * See accompanying file LICENSE.txt or copy at - * https://opensource.org/licenses/MIT - ***/ - -// Originally from: https://github.com/cr-marcstevens/sha1collisiondetection - -/* -// this file was generated by the 'parse_bitrel' program in the tools section -// using the data files from directory 'tools/data/3565' -// -// sha1_dvs contains a list of SHA-1 Disturbance Vectors (DV) to check -// dvType, dvK and dvB define the DV: I(K,B) or II(K,B) (see the paper) -// dm[80] is the expanded message block XOR-difference defined by the DV -// testt is the step to do the recompression from for collision detection -// maski and maskb define the bit to check for each DV in the dvmask returned by ubc_check -// -// ubc_check takes as input an expanded message block and verifies the unavoidable bitconditions for all listed DVs -// it returns a dvmask where each bit belonging to a DV is set if all unavoidable bitconditions for that DV have been met -// thus one needs to do the recompression check for each DV that has its bit set -*/ - -#ifndef SHA1DC_UBC_CHECK_H -#define SHA1DC_UBC_CHECK_H - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#ifndef SHA1DC_NO_STANDARD_INCLUDES -#include -#endif - -#define DVMASKSIZE 1 - typedef struct - { - int dvType; - int dvK; - int dvB; - int testt; - int maski; - int maskb; - uint32_t dm[80]; - } dv_info_t; - extern dv_info_t sha1_dvs[]; - void ubc_check(const uint32_t W[80], uint32_t dvmask[DVMASKSIZE]); - -#define DOSTORESTATE58 -#define DOSTORESTATE65 - -#define CHECK_DVMASK(_DVMASK) (0 != _DVMASK[0]) - -#if defined(__cplusplus) -} -#endif - -#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#include SHA1DC_CUSTOM_TRAILING_INCLUDE_UBC_CHECK_H -#endif - -#endif diff --git a/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c b/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c deleted file mode 100644 index 2794a563a4..0000000000 --- a/vendor/golang.org/x/crypto/ssh/test/sshd_test_pw.c +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// sshd_test_pw.c -// Wrapper to inject test password data for sshd PAM authentication -// -// This wrapper implements custom versions of getpwnam, getpwnam_r, -// getspnam and getspnam_r. These functions first call their real -// libc versions, then check if the requested user matches test user -// specified in env variable TEST_USER and if so replace the password -// with crypted() value of TEST_PASSWD env variable. -// -// Compile: -// gcc -Wall -shared -o sshd_test_pw.so -fPIC sshd_test_pw.c -// -// Compile with debug: -// gcc -DVERBOSE -Wall -shared -o sshd_test_pw.so -fPIC sshd_test_pw.c -// -// Run sshd: -// LD_PRELOAD="sshd_test_pw.so" TEST_USER="..." TEST_PASSWD="..." sshd ... - -// +build ignore - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#ifdef VERBOSE -#define DEBUG(X...) fprintf(stderr, X) -#else -#define DEBUG(X...) while (0) { } -#endif - -/* crypt() password */ -static char * -pwhash(char *passwd) { - return strdup(crypt(passwd, "$6$")); -} - -/* Pointers to real functions in libc */ -static struct passwd * (*real_getpwnam)(const char *) = NULL; -static int (*real_getpwnam_r)(const char *, struct passwd *, char *, size_t, struct passwd **) = NULL; -static struct spwd * (*real_getspnam)(const char *) = NULL; -static int (*real_getspnam_r)(const char *, struct spwd *, char *, size_t, struct spwd **) = NULL; - -/* Cached test user and test password */ -static char *test_user = NULL; -static char *test_passwd_hash = NULL; - -static void -init(void) { - /* Fetch real libc function pointers */ - real_getpwnam = dlsym(RTLD_NEXT, "getpwnam"); - real_getpwnam_r = dlsym(RTLD_NEXT, "getpwnam_r"); - real_getspnam = dlsym(RTLD_NEXT, "getspnam"); - real_getspnam_r = dlsym(RTLD_NEXT, "getspnam_r"); - - /* abort if env variables are not defined */ - if (getenv("TEST_USER") == NULL || getenv("TEST_PASSWD") == NULL) { - fprintf(stderr, "env variables TEST_USER and TEST_PASSWD are missing\n"); - abort(); - } - - /* Fetch test user and test password from env */ - test_user = strdup(getenv("TEST_USER")); - test_passwd_hash = pwhash(getenv("TEST_PASSWD")); - - DEBUG("sshd_test_pw init():\n"); - DEBUG("\treal_getpwnam: %p\n", real_getpwnam); - DEBUG("\treal_getpwnam_r: %p\n", real_getpwnam_r); - DEBUG("\treal_getspnam: %p\n", real_getspnam); - DEBUG("\treal_getspnam_r: %p\n", real_getspnam_r); - DEBUG("\tTEST_USER: '%s'\n", test_user); - DEBUG("\tTEST_PASSWD: '%s'\n", getenv("TEST_PASSWD")); - DEBUG("\tTEST_PASSWD_HASH: '%s'\n", test_passwd_hash); -} - -static int -is_test_user(const char *name) { - if (test_user != NULL && strcmp(test_user, name) == 0) - return 1; - return 0; -} - -/* getpwnam */ - -struct passwd * -getpwnam(const char *name) { - struct passwd *pw; - - DEBUG("sshd_test_pw getpwnam(%s)\n", name); - - if (real_getpwnam == NULL) - init(); - if ((pw = real_getpwnam(name)) == NULL) - return NULL; - - if (is_test_user(name)) - pw->pw_passwd = strdup(test_passwd_hash); - - return pw; -} - -/* getpwnam_r */ - -int -getpwnam_r(const char *name, - struct passwd *pwd, - char *buf, - size_t buflen, - struct passwd **result) { - int r; - - DEBUG("sshd_test_pw getpwnam_r(%s)\n", name); - - if (real_getpwnam_r == NULL) - init(); - if ((r = real_getpwnam_r(name, pwd, buf, buflen, result)) != 0 || *result == NULL) - return r; - - if (is_test_user(name)) - pwd->pw_passwd = strdup(test_passwd_hash); - - return 0; -} - -/* getspnam */ - -struct spwd * -getspnam(const char *name) { - struct spwd *sp; - - DEBUG("sshd_test_pw getspnam(%s)\n", name); - - if (real_getspnam == NULL) - init(); - if ((sp = real_getspnam(name)) == NULL) - return NULL; - - if (is_test_user(name)) - sp->sp_pwdp = strdup(test_passwd_hash); - - return sp; -} - -/* getspnam_r */ - -int -getspnam_r(const char *name, - struct spwd *spbuf, - char *buf, - size_t buflen, - struct spwd **spbufp) { - int r; - - DEBUG("sshd_test_pw getspnam_r(%s)\n", name); - - if (real_getspnam_r == NULL) - init(); - if ((r = real_getspnam_r(name, spbuf, buf, buflen, spbufp)) != 0) - return r; - - if (is_test_user(name)) - spbuf->sp_pwdp = strdup(test_passwd_hash); - - return r; -} diff --git a/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h b/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h deleted file mode 100644 index 9fc115b35f..0000000000 --- a/vendor/golang.org/x/tools/go/loader/testdata/issue46877/x.h +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -typedef int myint; diff --git a/vendor/modules.txt b/vendor/modules.txt index b0c7c79e97..b613a69a2e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -565,7 +565,7 @@ github.com/pingcap/errors # github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4 => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 ## explicit; go 1.13 github.com/pingcap/log -# github.com/pingcap/parser v3.0.12+incompatible => github.com/sjjian/parser v0.0.0-20240305095250-688ad439ef31 +# github.com/pingcap/parser v3.0.12+incompatible => github.com/sjjian/parser v0.0.0-20240704052347-b6199b7bccae ## explicit; go 1.13 github.com/pingcap/parser github.com/pingcap/parser/ast @@ -933,6 +933,6 @@ vitess.io/vitess/go/vt/vtgate/evalengine # cloud.google.com/go/compute/metadata => cloud.google.com/go/compute/metadata v0.1.0 # github.com/labstack/echo/v4 => github.com/labstack/echo/v4 v4.6.1 # github.com/pingcap/log => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 -# github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240305095250-688ad439ef31 +# github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240704052347-b6199b7bccae # github.com/swaggo/swag => github.com/swaggo/swag v1.6.7 # google.golang.org/grpc => google.golang.org/grpc v1.29.0