Let x = side of square base,

and y = height of prism

And assume that the prism is a right rectangular prism, or the the base and the height are perpendicular.

In the square base:

diagonal = d .....given

So, by Pythagorean theorem, d^2 = x^ +x^2

x^2 = (d^2) /2

x = d / (sqrt(2))

Area of all the faces of the prism:

A = 2(x^2) +4(x*y) = b .....given

2x^2 +4xy = b

4xy = b -2x^2

y = (b -2x^2) / (4x)

y = [b -2(d^2 / 2)] / [4(d / sqrt(2)]

y = [b -d^2] / [2sqrt(2) *d]

Simplify further if you like...

Therefore, the sum of all the edges of this prism is

= 8x +4y

= [8(d / sqrt(2)] +[4(b -d^2) / (2sqrt(2) *d)]

= [4sqrt(2) *d] + [2sqrt(2) *(b -d^2)/d]

= 2sqrt(2)*[2d +(b -d^2)/d]

= 2sqrt(2)[(2d^2 +b -d^2) / d]

= 2sqrt(2)[(b +d^2)/d] -----------------answer.