Skip to content
Snippets Groups Projects
  • Joe Tsai's avatar
    5961134f
    crypto: avoid escaping Hash.Sum on generic architectures · 5961134f
    Joe Tsai authored
    For architectures without a specialized implementation (e.g. arm),
    the generic implementation allocates because it does:
    
    	var block = blockGeneric
    
    which causes the compiler to give up trying to analyze block
    even though it is technically only ever one implementation.
    Instead of a variable, declare a function that wraps blockGeneric.
    
    We apply this fix to md5, sha1, and sha256,
    while sha512 already had the equivalent change.
    We add a test to all hashing packages to ensure no allocations.
    
    Credit goes to Cuong Manh Le for more specifically identifying
    the problem and Keith Randal for suggesting a concrete solution.
    
    Fixes #48055
    
    Change-Id: I1a6a2e028038e051c83fd72b10a8bf4d210df57d
    Reviewed-on: https://go-review.googlesource.com/c/go/+/346209
    
    
    Trust: Joe Tsai <joetsai@digital-static.net>
    Run-TryBot: Joe Tsai <joetsai@digital-static.net>
    Reviewed-by: default avatarFilippo Valsorda <filippo@golang.org>
    Reviewed-by: default avatarCuong Manh Le <cuong.manhle.vn@gmail.com>
    Reviewed-by: default avatarKeith Randall <khr@golang.org>
    TryBot-Result: Go Bot <gobot@golang.org>
    5961134f
    History
    crypto: avoid escaping Hash.Sum on generic architectures
    Joe Tsai authored
    For architectures without a specialized implementation (e.g. arm),
    the generic implementation allocates because it does:
    
    	var block = blockGeneric
    
    which causes the compiler to give up trying to analyze block
    even though it is technically only ever one implementation.
    Instead of a variable, declare a function that wraps blockGeneric.
    
    We apply this fix to md5, sha1, and sha256,
    while sha512 already had the equivalent change.
    We add a test to all hashing packages to ensure no allocations.
    
    Credit goes to Cuong Manh Le for more specifically identifying
    the problem and Keith Randal for suggesting a concrete solution.
    
    Fixes #48055
    
    Change-Id: I1a6a2e028038e051c83fd72b10a8bf4d210df57d
    Reviewed-on: https://go-review.googlesource.com/c/go/+/346209
    
    
    Trust: Joe Tsai <joetsai@digital-static.net>
    Run-TryBot: Joe Tsai <joetsai@digital-static.net>
    Reviewed-by: default avatarFilippo Valsorda <filippo@golang.org>
    Reviewed-by: default avatarCuong Manh Le <cuong.manhle.vn@gmail.com>
    Reviewed-by: default avatarKeith Randall <khr@golang.org>
    TryBot-Result: Go Bot <gobot@golang.org>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.