Exemple #1
0
    void parseHeaderLine(String line, KatResult kr) {
      Scanner lineScanner = new Scanner(line);
      lineScanner.findInLine(":Skein-(\\d+):\\s*(\\d+)-.*=\\s*(\\d+) bits(.*)");
      MatchResult result = null;
      try {
        result = lineScanner.match();
      } catch (Exception e) {
        System.out.println("Header line: " + line);
        e.printStackTrace();
        System.exit(1);
      }

      kr.stateSize = Integer.parseInt(result.group(1));
      kr.hashBitLength = Integer.parseInt(result.group(2));
      kr.msgLength = Integer.parseInt(result.group(3));
      kr.restOfLine = result.group(4);

      if ((kr.msgLength == 0) || (kr.msgLength % 8) != 0)
        kr.msg = new byte[(kr.msgLength >> 3) + 1];
      else kr.msg = new byte[kr.msgLength >> 3];

      if ((kr.hashBitLength % 8) != 0) kr.result = new byte[(kr.hashBitLength >> 3) + 1];
      else kr.result = new byte[kr.hashBitLength >> 3];

      kr.msgFill = 0;
      kr.resultFill = 0;
      kr.macKeyFill = 0;
    }
Exemple #2
0
 void parseResultLine(String line, KatResult kr) {
   Scanner ls = new Scanner(line);
   while (ls.hasNext()) {
     try {
       kr.result[kr.resultFill++] = (byte) ls.nextInt(16);
     } catch (Exception e) {
       System.out.println("Result data: " + line);
       e.printStackTrace();
       System.exit(1);
     }
   }
 }
Exemple #3
0
 void parseMacKeyHeaderLine(String line, KatResult kr) {
   Scanner ls = new Scanner(line);
   ls.findInLine(".*=\\s*(\\d+) .*");
   MatchResult result = null;
   try {
     result = ls.match();
   } catch (Exception e) {
     System.out.println("Mac header: " + line);
     e.printStackTrace();
     System.exit(1);
   }
   kr.macKeyLen = Integer.parseInt(result.group(1));
   kr.macKey = new byte[kr.macKeyLen];
   state = MacKey;
 }
Exemple #4
0
 void parseMacKeyLine(String line, KatResult kr) {
   if (line.contains("(none)")) {
     return;
   }
   Scanner ls = new Scanner(line);
   while (ls.hasNext()) {
     try {
       kr.macKey[kr.macKeyFill++] = (byte) ls.nextInt(16);
     } catch (Exception e) {
       System.out.println("Mac key data: " + line);
       e.printStackTrace();
       System.exit(1);
     }
   }
 }
Exemple #5
0
    void parseLine(String line, KatResult kr) {

      line = line.trim();
      if (line.length() <= 1) return;

      if (line.startsWith("Message")) {
        state = Message;
        return;
      }
      if (line.startsWith("Result")) {
        state = Result;
        return;
      }
      if (line.startsWith("MAC")) {
        state = MacKeyHeader;
      }
      if (line.startsWith("------")) {
        state = Done;
        return;
      }

      switch (state) {
        case Start:
          if (line.startsWith(":Skein-")) {
            parseHeaderLine(line, kr);
          } else {
            System.out.println("Wrong format found");
            System.exit(1);
          }
          break;
        case Message:
          parseMessageLine(line, kr);
          break;
        case Result:
          parseResultLine(line, kr);
          break;
        case MacKey:
          parseMacKeyLine(line, kr);
          break;
        case MacKeyHeader:
          parseMacKeyHeaderLine(line, kr);
          break;
      }
    }
 private void readObject(ObjectInputStream instr) {
   System.exit(0);
 }