github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/ext/hash/blake2.go (about)

     1  package hash
     2  
     3  import (
     4  	"crypto"
     5  
     6  	"github.com/ncruces/go-sqlite3"
     7  	"github.com/ncruces/go-sqlite3/internal/util"
     8  )
     9  
    10  func blake2sFunc(ctx sqlite3.Context, arg ...sqlite3.Value) {
    11  	hashFunc(ctx, arg[0], crypto.BLAKE2s_256)
    12  }
    13  
    14  func blake2bFunc(ctx sqlite3.Context, arg ...sqlite3.Value) {
    15  	size := 512
    16  	if len(arg) > 1 {
    17  		size = arg[1].Int()
    18  	}
    19  
    20  	switch size {
    21  	case 256:
    22  		hashFunc(ctx, arg[0], crypto.BLAKE2b_256)
    23  	case 384:
    24  		hashFunc(ctx, arg[0], crypto.BLAKE2b_384)
    25  	case 512:
    26  		hashFunc(ctx, arg[0], crypto.BLAKE2b_512)
    27  	default:
    28  		ctx.ResultError(util.ErrorString("blake2b: size must be 256, 384, 512"))
    29  	}
    30  }