Also, an alternative:
```javascript
var pad = new Buffer(32 - buffer.length)
pad.fill(0)
return Buffer.concat(pad, buffer)
```