              0xd7a7, 0x3dfb, 0x0099, 0x2b4d,
              0xdf0b, 0x4fc1, 0x2480, 0x2b83] )
 
-func ts64(_ x: inout [Int], _ i: Int, _ h:Int, _ l:Int) {
-  x[i]   = ( (h >> 24) & 0xff )
-  x[i+1] = ( (h >> 16) & 0xff )
-  x[i+2] = ( (h >>  8) & 0xff )
-  x[i+3] = ( h & 0xff )
-  x[i+4] = ( (l >> 24) & 0xff )
-  x[i+5] = ( (l >> 16) & 0xff )
-  x[i+6] = ( (l >>  8) & 0xff )
-  x[i+7] = ( l & 0xff )
-}
-
-func vn(_ x:[Int], _ xi:Int, _ y:[Int], _ yi:Int, _ n:Int) -> Int {
-    var d: Int = 0
+func ts64(_ x: inout [UInt8], _ i: Int, _ h:Int, _ l:Int) {
+  x[i]   = UInt8( (h >> 24) & 0xff )
+  x[i+1] = UInt8( (h >> 16) & 0xff )
+  x[i+2] = UInt8( (h >>  8) & 0xff )
+  x[i+3] = UInt8( h & 0xff )
+  x[i+4] = UInt8( (l >> 24) & 0xff )
+  x[i+5] = UInt8( (l >> 16) & 0xff )
+  x[i+6] = UInt8 ( (l >>  8) & 0xff )
+  x[i+7] = UInt8( l & 0xff )
+}
+
+func vn(_ x:[UInt8], _ xi:Int, _ y:[UInt8], _ yi:Int, _ n:Int) -> Int {
+    var d: UInt8 = 0
     for i in 0..<n {
         d = d | ( x[xi+i] ^ y[yi+i] )
     }
-    return (1 & ( (d - 1 ) >>> 8 ) ) - 1
-}
-
-func crypto_verify_32(_ x:[Int], _ xi:Int, _ y:[Int], _ yi:Int) -> Int {
+    return (1 & ( ( Int(d) - 1 ) >>> 8 ) ) - 1
+}
+
+func crypto_verify_32(_ x:[UInt8], _ xi:Int, _ y:[UInt8], _ yi:Int) -> Int {
   return vn(x,xi,y,yi,32)
 }
 


// Converts Curve25519 public key back to Ed25519 public key.
// edwardsY = (montgomeryX - 1) / (montgomeryX + 1)
func convertPublicKey(_ pk: [Int]) -> [Int] {
  var z = [Int](repeating: 0, count: 32)
  var x = gf()
  var a = gf()
  var b = gf()

        sel25519(&t, &m, Int(1-b) )
    }
    for i in 0..<16 {
        o[2*i] = UInt8(t[i] & 0xff ) // *** R
        o[2*i+1] = UInt8(t[i] >> 8 ) // *** R
    }
}

func neq25519(_ a:[Int64], _ b:[Int64]) -> Int {
  var c = [UInt8](repeating: 0, count: 32)
  var d = [UInt8](repeating: 0, count: 32)
  pack25519(&c, a)
  pack25519(&d, b)
  return crypto_verify_32(c, 0, d, 0)
}

func par25519(_ a:[Int64]) -> Int {
  var d = [UInt8](repeating: 0, count: 32)
  pack25519(&d, a)
  return Int(d[0]) & 1
}

func unpack25519(_ o:inout [Int64], _ n:[UInt8]) {
    for i in 0..<16 {
        o[i] = Int64(n[2*i]) + ( Int64(n[2*i+1]) << 8) // *** R 
    }
    o[15] = o[15] & 0x7fff
}
